From 27f8e4e384247966797f563455a05207a9634768 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Mon, 12 Jun 2023 20:24:05 -0500 Subject: [PATCH 1/8] [Refactor] StreamIO and OpenSearchException foundation to core library This commit refactors the Stream IO classes from the server to core library to support cloud native and serverless extensions. The following classes are refactored: * StreamInput * StreamOutput * Writeable * NamedWriteable * NamedWriteableRegistry * Index * ShardId * BytesReference * ByteArray * BigArray * SecureString * Text * ParsingException * RestStatus The namespace is left unchanged but will be refactored in a follow up commit to avoid split package in order to support jigsaw modularity. Signed-off-by: Nicholas Walter Knize --- .../opensearch/client/GetAliasesResponse.java | 9 +- .../opensearch/client/RequestConverters.java | 5 +- .../client/core/TermVectorsRequest.java | 3 +- .../client/indices/CreateIndexRequest.java | 11 +- .../indices/GetFieldMappingsResponse.java | 3 +- .../indices/PutIndexTemplateRequest.java | 11 +- .../client/indices/PutMappingRequest.java | 3 +- .../java/org/opensearch/client/CrudIT.java | 3 +- .../org/opensearch/client/IngestClientIT.java | 14 +- ...OpenSearchRestHighLevelClientTestCase.java | 8 +- .../client/RequestConvertersTests.java | 5 +- .../client/RestHighLevelClientTests.java | 4 +- .../java/org/opensearch/client/SearchIT.java | 8 +- .../client/SearchPipelineClientIT.java | 8 +- .../core/tasks/GetTaskResponseTests.java | 4 +- .../documentation/CRUDDocumentationIT.java | 5 +- .../IndicesClientDocumentationIT.java | 3 +- .../StoredScriptsDocumentationIT.java | 6 +- .../TasksClientDocumentationIT.java | 4 +- .../GetIndexTemplatesResponseTests.java | 5 +- .../tasks/CancelTasksResponseTests.java | 3 +- .../org/opensearch/BaseExceptionsHelper.java | 40 +- .../opensearch/BaseOpenSearchException.java | 356 +++++++++- .../action/ShardOperationFailedException.java | 0 .../DefaultShardOperationFailedException.java | 12 +- .../opensearch/common/ParsingException.java | 7 +- .../common/bytes/AbstractBytesReference.java | 2 +- .../opensearch/common/bytes/BytesArray.java | 0 .../common/bytes/BytesReference.java | 17 - .../common/bytes/CompositeBytesReference.java | 0 .../common/bytes/PagedBytesReference.java | 7 +- .../common/compress/NotXContentException.java | 0 .../io/stream/InputStreamStreamInput.java | 6 +- .../common/io/stream/NamedWriteable.java | 0 .../io/stream/NamedWriteableRegistry.java | 1 + .../NotSerializableExceptionWrapper.java | 11 +- .../common/io/stream/StreamInput.java | 331 ++++++++- .../common/io/stream/StreamOutput.java | 171 ++++- .../common/io/stream/Writeable.java | 178 +++++ .../common/settings/SecureString.java | 0 .../java/org/opensearch/common/text/Text.java | 0 .../org/opensearch/common/util/BigArray.java | 0 .../org/opensearch/common/util/ByteArray.java | 0 .../common/xcontent/XContentParserUtils.java | 0 .../core/common/io/StreamsUtil.java | 34 + .../main/java/org/opensearch/index/Index.java | 0 .../org/opensearch/index/shard/ShardId.java | 4 +- .../IndexShardSnapshotException.java | 4 +- .../IndexShardSnapshotFailedException.java | 0 .../java/org/opensearch/rest/RestStatus.java | 0 .../xcontent/MapXContentParserTests.java | 6 +- .../common/xcontent/XContentParserTests.java | 8 +- .../ingest/common/ScriptProcessor.java | 4 +- .../common/GrokProcessorGetActionTests.java | 5 +- .../ingest/common/JsonProcessorTests.java | 4 +- .../geoip/GeoIpProcessorNonIngestNodeIT.java | 3 +- .../mustache/MultiSearchTemplateRequest.java | 6 +- .../mustache/SearchTemplateResponse.java | 9 +- .../script/mustache/MustacheTests.java | 6 +- .../SearchTemplateRequestXContentTests.java | 6 +- .../mustache/SearchTemplateResponseTests.java | 9 +- .../action/PainlessExecuteAction.java | 3 +- .../action/PainlessExecuteRequestTests.java | 5 +- .../RankFeatureMetaFieldMapperTests.java | 3 +- .../mapper/ScaledFloatFieldMapperTests.java | 20 +- .../mapper/ParentJoinFieldMapperTests.java | 38 +- .../percolator/PercolatorQuerySearchIT.java | 81 +-- .../percolator/PercolateQueryBuilder.java | 3 +- .../PercolateQueryBuilderTests.java | 3 +- .../PercolatorFieldMapperTests.java | 36 +- .../PercolatorQuerySearchTests.java | 15 +- .../index/rankeval/RankEvalResponse.java | 3 +- .../index/rankeval/RankEvalResponseTests.java | 6 +- .../index/rankeval/RankEvalSpecTests.java | 3 +- .../AbstractBulkByQueryRestHandler.java | 4 +- .../opensearch/index/reindex/Reindexer.java | 4 +- .../reindex/remote/RemoteResponseParsers.java | 4 +- .../index/reindex/RestReindexActionTests.java | 4 +- .../common/FilterQueryRequestProcessor.java | 4 +- .../common/RenameFieldResponseProcessor.java | 3 +- .../common/ScriptRequestProcessor.java | 4 +- .../index/mapper/size/SizeMappingTests.java | 7 +- .../gcs/GoogleCloudStorageServiceTests.java | 3 +- ...rossClusterSearchUnavailableClusterIT.java | 13 +- .../http/DetailedErrorsEnabledIT.java | 2 +- .../admin/cluster/node/tasks/TasksIT.java | 4 +- .../action/bulk/BulkIntegrationIT.java | 4 +- .../java/org/opensearch/get/GetActionIT.java | 3 +- .../org/opensearch/ingest/IngestClientIT.java | 27 +- ...gestProcessorNotInstalledOnAllNodesIT.java | 3 +- .../org/opensearch/mget/SimpleMgetIT.java | 3 +- .../aggregations/FiltersAggsRewriteIT.java | 3 +- .../search/fields/SearchFieldsIT.java | 3 +- .../opensearch/search/geo/GeoFilterIT.java | 9 +- .../search/scroll/SearchScrollIT.java | 4 +- .../SnapshotCustomPluginStateIT.java | 3 +- .../org/opensearch/update/UpdateNoopIT.java | 4 +- .../java/org/opensearch/ExceptionsHelper.java | 21 - .../org/opensearch/OpenSearchException.java | 649 +++++------------- .../OpenSearchSecurityException.java | 2 +- .../action/TaskOperationFailure.java | 6 +- .../ClusterDeleteWeightedRoutingRequest.java | 3 +- .../put/ClusterPutWeightedRoutingRequest.java | 3 +- .../create/CreateSnapshotRequest.java | 4 +- .../indices/create/CreateIndexRequest.java | 9 +- .../mapping/get/GetFieldMappingsResponse.java | 3 +- .../mapping/put/PutMappingRequest.java | 5 +- .../template/put/PutIndexTemplateRequest.java | 9 +- .../action/bulk/BulkItemResponse.java | 14 +- .../action/get/MultiGetResponse.java | 5 +- .../opensearch/action/index/IndexRequest.java | 3 +- .../action/ingest/GetPipelineResponse.java | 4 +- .../ingest/SimulateDocumentBaseResult.java | 2 +- .../ingest/SimulateProcessorResult.java | 8 +- .../search/GetSearchPipelineResponse.java | 4 +- .../action/search/MultiSearchRequest.java | 5 +- .../action/search/MultiSearchResponse.java | 4 +- .../search/SearchPhaseExecutionException.java | 2 +- .../action/search/ShardSearchFailure.java | 9 +- .../replication/ReplicationOperation.java | 3 +- .../replication/ReplicationResponse.java | 6 +- .../TransportBroadcastReplicationAction.java | 4 +- .../support/tasks/BaseTasksResponse.java | 9 +- .../termvectors/TermVectorsRequest.java | 3 +- .../action/update/UpdateHelper.java | 3 +- .../cluster/metadata/AliasMetadata.java | 4 +- .../cluster/metadata/MappingMetadata.java | 4 +- .../MetadataIndexTemplateService.java | 4 +- .../java/org/opensearch/common/Strings.java | 3 +- .../io/stream/ByteBufferStreamInput.java | 2 +- .../common/io/stream/BytesStreamInput.java | 2 +- .../common/io/stream/FilterStreamInput.java | 2 +- .../common/io/stream/Streamables.java | 13 +- .../common/io/stream/Writeable.java | 88 --- .../common/util/BytesReferenceUtil.java | 33 + .../common/util/PageCacheRecycler.java | 3 +- .../xcontent/JsonToStringXContentParser.java | 4 +- .../common/xcontent/ObjectParserHelper.java | 3 +- .../common/xcontent/XContentHelper.java | 7 +- .../org/opensearch/index/get/GetResult.java | 3 +- .../opensearch/index/get/ShardGetService.java | 5 +- .../index/mapper/MappedFieldType.java | 5 +- .../index/query/MoreLikeThisQueryBuilder.java | 5 +- .../functionscore/DecayFunctionBuilder.java | 3 +- .../functionscore/DecayFunctionParser.java | 3 +- .../index/reindex/BulkByScrollResponse.java | 10 +- .../index/reindex/ReindexRequest.java | 4 +- .../opensearch/index/reindex/RemoteInfo.java | 5 +- .../index/reindex/ScrollableHitSource.java | 5 +- .../opensearch/index/shard/IndexShard.java | 3 +- .../opensearch/ingest/ConfigurationUtils.java | 4 +- .../ingest/PipelineConfiguration.java | 3 +- .../blobstore/BlobStoreRepository.java | 5 +- .../opensearch/rest/BytesRestResponse.java | 12 +- .../opensearch/rest/RestRequestFilter.java | 3 +- .../java/org/opensearch/script/Script.java | 4 +- .../java/org/opensearch/search/SearchHit.java | 3 +- .../fetch/subphase/FetchSourcePhase.java | 4 +- .../pipeline/PipelineConfiguration.java | 3 +- .../CompletionSuggestionBuilder.java | 5 +- .../java/org/opensearch/tasks/TaskResult.java | 3 +- .../ExceptionSerializationTests.java | 12 +- .../org/opensearch/ExceptionsHelperTests.java | 9 +- .../opensearch/OpenSearchExceptionTests.java | 77 ++- .../action/DocWriteResponseTests.java | 6 +- .../node/tasks/TransportTasksActionTests.java | 4 +- .../RestoreRemoteStoreRequestTests.java | 4 +- .../stats/RemoteStoreStatsResponseTests.java | 9 +- .../stats/RemoteStoreStatsTests.java | 4 +- .../put/PutRepositoryRequestTests.java | 4 +- .../reroute/ClusterRerouteRequestTests.java | 4 +- .../ClusterUpdateSettingsRequestTests.java | 3 +- .../create/CreateSnapshotRequestTests.java | 4 +- .../restore/RestoreSnapshotRequestTests.java | 4 +- .../PutStoredScriptRequestTests.java | 5 +- .../indices/analyze/AnalyzeResponseTests.java | 5 +- .../rollover/RolloverRequestTests.java | 3 +- .../IndicesShardStoreResponseTests.java | 3 +- .../action/bulk/BulkItemResponseTests.java | 10 +- .../action/bulk/BulkResponseTests.java | 4 +- .../action/explain/ExplainResponseTests.java | 4 +- .../MergedFieldCapabilitiesResponseTests.java | 4 +- .../get/TransportMultiGetActionTests.java | 6 +- .../ingest/GetPipelineResponseTests.java | 6 +- .../ingest/PutPipelineRequestTests.java | 7 +- .../ingest/WriteableIngestDocumentTests.java | 4 +- .../search/MultiSearchRequestTests.java | 4 +- .../SearchPhaseExecutionExceptionTests.java | 6 +- ...ultShardOperationFailedExceptionTests.java | 4 +- .../action/support/IndicesOptionsTests.java | 7 +- .../replication/ReplicationResponseTests.java | 6 +- .../TransportMultiTermVectorsActionTests.java | 6 +- .../action/update/UpdateRequestTests.java | 3 +- .../CoordinationMetadataTests.java | 6 +- .../OpenSearchNodeCommandTests.java | 4 +- .../cluster/metadata/IndexGraveyardTests.java | 4 +- .../cluster/metadata/IndexMetadataTests.java | 4 +- .../metadata/IndexTemplateMetadataTests.java | 3 +- .../cluster/metadata/ManifestTests.java | 3 +- .../cluster/metadata/MetadataTests.java | 11 +- .../cluster/routing/AllocationIdTests.java | 3 +- .../common/geo/GeoJsonSerializationTests.java | 4 +- .../opensearch/common/geo/GeoUtilTests.java | 4 +- .../common/io/stream/BytesStreamsTests.java | 2 +- .../common/xcontent/BaseXContentTestCase.java | 35 +- .../common/xcontent/XContentFactoryTests.java | 3 +- .../builder/XContentBuilderTests.java | 8 +- .../cbor/CborXContentParserTests.java | 3 +- .../support/AbstractFilteringTestCase.java | 5 +- .../xcontent/support/XContentHelperTests.java | 5 +- .../support/XContentMapValuesTests.java | 32 +- .../AbstractXContentFilteringTestCase.java | 6 +- .../java/org/opensearch/index/IndexTests.java | 4 +- .../index/IndexingSlowLogTests.java | 5 +- .../fielddata/BinaryDVFieldDataTests.java | 10 +- .../mapper/CompletionFieldMapperTests.java | 4 +- .../index/mapper/CopyToMapperTests.java | 4 +- .../mapper/DataStreamFieldMapperTests.java | 12 +- .../index/mapper/DynamicMappingTests.java | 3 +- .../mapper/FieldNamesFieldMapperTests.java | 8 +- .../mapper/FlatObjectFieldDataTests.java | 4 +- .../index/mapper/IdFieldMapperTests.java | 4 +- .../index/mapper/IndexFieldMapperTests.java | 4 +- .../index/mapper/IpRangeFieldMapperTests.java | 4 +- .../mapper/JavaMultiFieldMergeTests.java | 5 +- .../index/mapper/MapperServiceTests.java | 24 +- .../index/mapper/NestedObjectMapperTests.java | 38 +- .../mapper/NullValueObjectMappingTests.java | 10 +- .../index/mapper/RoutingFieldMapperTests.java | 6 +- .../index/mapper/SourceFieldMapperTests.java | 10 +- .../mapper/StoredNumericValuesTests.java | 4 +- .../index/mapper/TypeParsersTests.java | 4 +- .../index/mapper/UpdateMappingTests.java | 4 +- .../index/reindex/ReindexRequestTests.java | 7 +- .../search/geo/GeoPointParsingTests.java | 28 +- .../snapshots/blobstore/FileInfoTests.java | 5 +- ...oteStoreShardShallowCopySnapshotTests.java | 3 +- .../ingest/PipelineConfigurationTests.java | 3 +- .../opensearch/repositories/IndexIdTests.java | 4 +- .../repositories/RepositoryDataTests.java | 4 +- .../rest/BytesRestResponseTests.java | 6 +- .../opensearch/rest/RestControllerTests.java | 3 +- .../rest/action/RestMainActionTests.java | 3 +- .../indices/RestCreateIndexActionTests.java | 8 +- .../script/ScriptMetadataTests.java | 26 +- .../opensearch/script/ScriptServiceTests.java | 3 +- .../script/StoredScriptSourceTests.java | 4 +- .../opensearch/script/StoredScriptTests.java | 26 +- .../aggregations/AggregationsTests.java | 3 +- .../AggregatorFactoriesTests.java | 3 +- .../bucket/histogram/DoubleBoundsTests.java | 5 +- .../bucket/histogram/LongBoundsTests.java | 5 +- .../metrics/InternalTopHitsTests.java | 6 +- .../builder/SearchSourceBuilderTests.java | 7 +- .../fetch/subphase/FetchSourcePhaseTests.java | 4 +- .../fetch/subphase/FieldFetcherTests.java | 4 +- .../searchafter/SearchAfterBuilderTests.java | 4 +- .../search/suggest/SuggestTests.java | 3 +- .../CategoryContextMappingTests.java | 52 +- .../completion/GeoContextMappingTests.java | 20 +- .../completion/GeoQueryContextTests.java | 6 +- .../snapshots/SnapshotRequestsTests.java | 5 +- .../tasks/ListTasksResponseTests.java | 16 +- .../org/opensearch/tasks/TaskInfoTests.java | 4 +- .../ThreadPoolSerializationTests.java | 6 +- .../index/engine/EngineTestCase.java | 3 +- .../index/mapper/MapperServiceTestCase.java | 6 +- .../index/mapper/MapperTestCase.java | 8 +- .../search/RandomSearchRequestGenerator.java | 4 +- .../AbstractSnapshotIntegTestCase.java | 5 +- .../test/AbstractXContentTestCase.java | 5 +- .../test/OpenSearchIntegTestCase.java | 13 +- .../opensearch/test/OpenSearchTestCase.java | 7 +- .../org/opensearch/test/RandomObjects.java | 3 +- .../opensearch/test/XContentTestUtils.java | 7 +- .../test/hamcrest/OpenSearchAssertions.java | 5 +- .../yaml/ClientYamlTestExecutionContext.java | 4 +- .../test/AbstractXContentTestCaseTests.java | 3 +- .../test/XContentTestUtilsTests.java | 20 +- .../hamcrest/OpenSearchAssertionsTests.java | 34 +- .../test/rest/yaml/ObjectPathTests.java | 22 +- .../test/test/OpenSearchTestCaseTests.java | 3 +- 282 files changed, 2277 insertions(+), 1505 deletions(-) rename {server => libs/core}/src/main/java/org/opensearch/action/ShardOperationFailedException.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java (91%) rename {server => libs/core}/src/main/java/org/opensearch/common/ParsingException.java (93%) rename {server => libs/core}/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java (99%) rename {server => libs/core}/src/main/java/org/opensearch/common/bytes/BytesArray.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/bytes/BytesReference.java (90%) rename {server => libs/core}/src/main/java/org/opensearch/common/bytes/CompositeBytesReference.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java (94%) rename {server => libs/core}/src/main/java/org/opensearch/common/compress/NotXContentException.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java (95%) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/NamedWriteable.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java (99%) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java (89%) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/StreamInput.java (74%) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/StreamOutput.java (88%) create mode 100644 libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java rename {server => libs/core}/src/main/java/org/opensearch/common/settings/SecureString.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/text/Text.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/util/BigArray.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/util/ByteArray.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/common/xcontent/XContentParserUtils.java (100%) create mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java rename {server => libs/core}/src/main/java/org/opensearch/index/Index.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/index/shard/ShardId.java (96%) rename {server => libs/core}/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java (93%) rename {server => libs/core}/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotFailedException.java (100%) rename {server => libs/core}/src/main/java/org/opensearch/rest/RestStatus.java (100%) delete mode 100644 server/src/main/java/org/opensearch/common/io/stream/Writeable.java create mode 100644 server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java b/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java index 83b00df73bdc4..3acd4d515da4f 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java @@ -32,6 +32,7 @@ package org.opensearch.client; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.common.xcontent.StatusToXContentObject; @@ -63,7 +64,7 @@ public class GetAliasesResponse implements StatusToXContentObject { private final RestStatus status; private final String error; - private final OpenSearchException exception; + private final BaseOpenSearchException exception; private final Map> aliases; @@ -74,7 +75,7 @@ public class GetAliasesResponse implements StatusToXContentObject { this.exception = null; } - private GetAliasesResponse(RestStatus status, OpenSearchException exception) { + private GetAliasesResponse(RestStatus status, BaseOpenSearchException exception) { this.status = status; this.error = null; this.aliases = Collections.emptyMap(); @@ -96,7 +97,7 @@ public String getError() { /** * Return the exception that may have been returned */ - public OpenSearchException getException() { + public BaseOpenSearchException getException() { return exception; } @@ -147,7 +148,7 @@ public static GetAliasesResponse fromXContent(XContentParser parser) throws IOEx String currentFieldName; Token token; String error = null; - OpenSearchException exception = null; + BaseOpenSearchException exception = null; RestStatus status = RestStatus.OK; while (parser.nextToken() != Token.END_OBJECT) { diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java index 007761d9ab473..ffdf3c3e290c7 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java @@ -76,6 +76,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -236,7 +237,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException { } metadata.endObject(); - BytesRef metadataSource = BytesReference.bytes(metadata).toBytesRef(); + BytesRef metadataSource = BytesReferenceUtil.bytes(metadata).toBytesRef(); content.write(metadataSource.bytes, metadataSource.offset, metadataSource.length); content.write(separator); } @@ -262,7 +263,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException { ) { try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) { builder.copyCurrentStructure(parser); - source = BytesReference.bytes(builder).toBytesRef(); + source = BytesReferenceUtil.bytes(builder).toBytesRef(); } } } else if (opType == DocWriteRequest.OpType.UPDATE) { diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java index 2384cef68ade0..bf0456a6c9221 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java @@ -35,6 +35,7 @@ import org.opensearch.client.Validatable; import org.opensearch.common.Nullable; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; @@ -280,7 +281,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (perFieldAnalyzer != null) builder.field("per_field_analyzer", perFieldAnalyzer); if (docBuilder != null) { - BytesReference doc = BytesReference.bytes(docBuilder); + BytesReference doc = BytesReferenceUtil.bytes(docBuilder); try (InputStream stream = doc.streamInput()) { builder.rawField("doc", stream, docBuilder.contentType()); } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java index 2206e732aa00e..0a5f1070722a4 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java @@ -42,6 +42,7 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -201,7 +202,7 @@ public CreateIndexRequest mapping(String source, MediaType mediaType) { * @param source The mapping source */ public CreateIndexRequest mapping(XContentBuilder source) { - return mapping(BytesReference.bytes(source), source.contentType()); + return mapping(BytesReferenceUtil.bytes(source), source.contentType()); } /** @@ -215,7 +216,7 @@ public CreateIndexRequest mapping(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); - return mapping(BytesReference.bytes(builder), builder.contentType()); + return mapping(BytesReferenceUtil.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -265,7 +266,7 @@ public CreateIndexRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReference.bytes(builder), builder.contentType()); + return aliases(BytesReferenceUtil.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -275,7 +276,7 @@ public CreateIndexRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public CreateIndexRequest aliases(XContentBuilder source) { - return aliases(BytesReference.bytes(source), source.contentType()); + return aliases(BytesReferenceUtil.bytes(source), source.contentType()); } /** @@ -372,7 +373,7 @@ public CreateIndexRequest source(String source, MediaType mediaType) { * Note that the mapping definition should *not* be nested under a type name. */ public CreateIndexRequest source(XContentBuilder source) { - return source(BytesReference.bytes(source), source.contentType()); + return source(BytesReferenceUtil.bytes(source), source.contentType()); } /** diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java index 091c7f39e41da..f480bfded7daa 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java @@ -32,6 +32,7 @@ package org.opensearch.client.indices; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ConstructingObjectParser; @@ -129,7 +130,7 @@ public static class FieldMappingMetadata { PARSER.declareField(optionalConstructorArg(), (p, c) -> p.text(), FULL_NAME, ObjectParser.ValueType.STRING); PARSER.declareField(optionalConstructorArg(), (p, c) -> { final XContentBuilder jsonBuilder = jsonBuilder().copyCurrentStructure(p); - final BytesReference bytes = BytesReference.bytes(jsonBuilder); + final BytesReference bytes = BytesReferenceUtil.bytes(jsonBuilder); return bytes; }, MAPPING, ObjectParser.ValueType.OBJECT); } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java index c6d6a29a02af1..468b308e63608 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java @@ -42,6 +42,7 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -241,7 +242,7 @@ public String cause() { * @param source The mapping source */ public PutIndexTemplateRequest mapping(XContentBuilder source) { - internalMapping(XContentHelper.convertToMap(BytesReference.bytes(source), true, source.contentType()).v2()); + internalMapping(XContentHelper.convertToMap(BytesReferenceUtil.bytes(source), true, source.contentType()).v2()); return this; } @@ -272,7 +273,7 @@ private PutIndexTemplateRequest internalMapping(Map source) { MediaType mediaType = builder.contentType(); Objects.requireNonNull(mediaType); try { - mappings = new BytesArray(XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, mediaType)); + mappings = new BytesArray(XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder), false, false, mediaType)); return this; } catch (IOException e) { throw new UncheckedIOException("failed to convert source to json", e); @@ -291,7 +292,7 @@ public BytesReference mappings() { */ public PutIndexTemplateRequest source(XContentBuilder templateBuilder) { try { - return source(BytesReference.bytes(templateBuilder), templateBuilder.contentType()); + return source(BytesReferenceUtil.bytes(templateBuilder), templateBuilder.contentType()); } catch (Exception e) { throw new IllegalArgumentException("Failed to build json for template request", e); } @@ -421,7 +422,7 @@ public PutIndexTemplateRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReference.bytes(builder)); + return aliases(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -431,7 +432,7 @@ public PutIndexTemplateRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public PutIndexTemplateRequest aliases(XContentBuilder source) { - return aliases(BytesReference.bytes(source)); + return aliases(BytesReferenceUtil.bytes(source)); } /** diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java index 3d05c12b7ba1f..fbd32ddae2e26 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java @@ -38,6 +38,7 @@ import org.opensearch.client.TimedRequest; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.MediaType; @@ -160,7 +161,7 @@ public PutMappingRequest source(String mappingSource, MediaType mediaType) { * Note that the definition should *not* be nested under a type name. */ public PutMappingRequest source(XContentBuilder builder) { - this.source = BytesReference.bytes(builder); + this.source = BytesReferenceUtil.bytes(builder); this.mediaType = builder.contentType(); return this; } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java index 06a6fb6802e3c..ea3ef8e152861 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java @@ -62,6 +62,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -862,7 +863,7 @@ public void testBulk() throws IOException { bulkRequest.add(deleteRequest); } else { - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( XContentBuilder.builder(xContentType.xContent()).startObject().field("id", i).endObject() ); if (opType == DocWriteRequest.OpType.INDEX) { diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java index 4e67198422b23..d6b13421bf4e2 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java @@ -42,7 +42,7 @@ import org.opensearch.action.ingest.SimulatePipelineRequest; import org.opensearch.action.ingest.SimulatePipelineResponse; import org.opensearch.action.support.master.AcknowledgedResponse; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.PipelineConfiguration; @@ -58,7 +58,7 @@ public class IngestClientIT extends OpenSearchRestHighLevelClientTestCase { public void testPutPipeline() throws IOException { String id = "some_pipeline_id"; XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); - PutPipelineRequest request = new PutPipelineRequest(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType()); + PutPipelineRequest request = new PutPipelineRequest(id, BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType()); AcknowledgedResponse putPipelineResponse = execute( request, @@ -72,7 +72,11 @@ public void testGetPipeline() throws IOException { String id = "some_pipeline_id"; XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); { - PutPipelineRequest request = new PutPipelineRequest(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType()); + PutPipelineRequest request = new PutPipelineRequest( + id, + BytesReferenceUtil.bytes(pipelineBuilder), + pipelineBuilder.contentType() + ); createPipeline(request); } @@ -87,7 +91,7 @@ public void testGetPipeline() throws IOException { assertEquals(response.pipelines().get(0).getId(), id); PipelineConfiguration expectedConfig = new PipelineConfiguration( id, - BytesReference.bytes(pipelineBuilder), + BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType() ); assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap()); @@ -162,7 +166,7 @@ private void testSimulatePipeline(boolean isVerbose, boolean isFailure) throws I builder.endObject(); SimulatePipelineRequest request = new SimulatePipelineRequest( - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), XContentType.fromMediaType(builder.contentType()) ); request.setVerbose(isVerbose); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java index c1e2420d86d20..07e0cb0fd88cd 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java @@ -48,8 +48,8 @@ import org.opensearch.client.indices.CreateIndexRequest; import org.opensearch.common.Booleans; import org.opensearch.common.CheckedRunnable; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -223,12 +223,12 @@ protected static void createFieldAddingPipleine(String id, String fieldName, Str .endArray() .endObject(); - createPipeline(new PutPipelineRequest(id, BytesReference.bytes(pipeline), XContentType.JSON)); + createPipeline(new PutPipelineRequest(id, BytesReferenceUtil.bytes(pipeline), XContentType.JSON)); } protected static void createPipeline(String pipelineId) throws IOException { XContentBuilder builder = buildRandomXContentPipeline(); - createPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(builder), builder.contentType())); + createPipeline(new PutPipelineRequest(pipelineId, BytesReferenceUtil.bytes(builder), builder.contentType())); } protected static void createPipeline(PutPipelineRequest putPipelineRequest) throws IOException { @@ -266,7 +266,7 @@ protected void putConflictPipeline() throws IOException { .endObject(); final PutPipelineRequest putPipelineRequest = new PutPipelineRequest( CONFLICT_PIPELINE_ID, - BytesReference.bytes(pipelineBuilder), + BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType() ); assertTrue(highLevelClient().ingest().putPipeline(putPipelineRequest, RequestOptions.DEFAULT).isAcknowledged()); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java index ca880d2f3d022..3e0db1179879d 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java @@ -72,6 +72,7 @@ import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -424,7 +425,7 @@ public void testReindex() throws IOException { "remote-host", 9200, null, - BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)), + BytesReferenceUtil.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)), "user", "pass", emptyMap(), @@ -1703,7 +1704,7 @@ public void testPutScript() throws Exception { builder.startObject("script").field("lang", "painless").field("source", "Math.log(_score * 2) + params.multiplier").endObject(); builder.endObject(); - putStoredScriptRequest.content(BytesReference.bytes(builder), xContentType); + putStoredScriptRequest.content(BytesReferenceUtil.bytes(builder), xContentType); } Map expectedParams = new HashMap<>(); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java index 85f329eb6e895..09f055730f72a 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java @@ -46,8 +46,8 @@ import org.opensearch.client.core.MainRequest; import org.opensearch.client.core.MainResponse; import org.opensearch.common.CheckedFunction; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -340,7 +340,7 @@ private static HttpEntity createBinaryEntity(XContentBuilder xContentBuilder, Co builder.startObject(); builder.field("field", "value"); builder.endObject(); - return new ByteArrayEntity(BytesReference.bytes(builder).toBytesRef().bytes, contentType); + return new ByteArrayEntity(BytesReferenceUtil.bytes(builder).toBytesRef().bytes, contentType); } } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java index 41d8ce2a2fed9..f55b9574e2e33 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java @@ -32,6 +32,7 @@ package org.opensearch.client; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchStatusException; import org.opensearch.action.explain.ExplainRequest; @@ -55,6 +56,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -827,8 +829,8 @@ public void testSearchScroll() throws Exception { () -> execute(scrollRequest, highLevelClient()::scroll, highLevelClient()::scrollAsync) ); assertEquals(RestStatus.NOT_FOUND, exception.status()); - assertThat(exception.getRootCause(), instanceOf(OpenSearchException.class)); - OpenSearchException rootCause = (OpenSearchException) exception.getRootCause(); + assertThat(exception.getRootCause(), instanceOf(BaseOpenSearchException.class)); + BaseOpenSearchException rootCause = (BaseOpenSearchException) exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("No search context found for")); } } @@ -1187,7 +1189,7 @@ public void testRenderSearchTemplate() throws IOException { ); assertNull(searchTemplateResponse.getResponse()); - BytesReference expectedSource = BytesReference.bytes( + BytesReference expectedSource = BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("query") diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java index ea27d8e9605d9..d13025e69da8e 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java @@ -13,7 +13,7 @@ import org.opensearch.action.search.GetSearchPipelineResponse; import org.opensearch.action.search.PutSearchPipelineRequest; import org.opensearch.action.support.master.AcknowledgedResponse; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -26,7 +26,7 @@ public void testPutPipeline() throws IOException { XContentBuilder pipelineBuilder = buildSearchPipeline(); PutSearchPipelineRequest request = new PutSearchPipelineRequest( id, - BytesReference.bytes(pipelineBuilder), + BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType() ); createPipeline(request); @@ -46,7 +46,7 @@ public void testGetPipeline() throws IOException { XContentBuilder pipelineBuilder = buildSearchPipeline(); PutSearchPipelineRequest request = new PutSearchPipelineRequest( id, - BytesReference.bytes(pipelineBuilder), + BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType() ); createPipeline(request); @@ -67,7 +67,7 @@ public void testDeletePipeline() throws IOException { XContentBuilder pipelineBuilder = buildSearchPipeline(); PutSearchPipelineRequest request = new PutSearchPipelineRequest( id, - BytesReference.bytes(pipelineBuilder), + BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType() ); createPipeline(request); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java index 01b980a95f1b1..2af978ac09c7e 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java @@ -34,7 +34,7 @@ import org.opensearch.client.Requests; import org.opensearch.client.tasks.GetTaskResponse; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.tasks.RawTaskStatus; @@ -132,7 +132,7 @@ private static RawTaskStatus randomRawTaskStatus() { builder.field(randomAlphaOfLength(5), randomAlphaOfLength(5)); } builder.endObject(); - return new RawTaskStatus(BytesReference.bytes(builder)); + return new RawTaskStatus(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java index 38addb91f0d41..b198d05e191bb 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java @@ -33,6 +33,7 @@ package org.opensearch.client.documentation; import org.apache.hc.core5.http.HttpHost; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.DocWriteRequest; @@ -1943,7 +1944,7 @@ public void testMultiGet() throws Exception { // tag::multi-get-indexnotfound assertNull(missingIndexItem.getResponse()); // <1> Exception e = missingIndexItem.getFailure().getFailure(); // <2> - OpenSearchException ee = (OpenSearchException) e; // <3> + BaseOpenSearchException ee = (BaseOpenSearchException) e; // <3> // TODO status is broken! fix in a followup // assertEquals(RestStatus.NOT_FOUND, ee.status()); // <4> assertThat(e.getMessage(), @@ -2035,7 +2036,7 @@ public void onFailure(Exception e) { MultiGetItemResponse item = response.getResponses()[0]; assertNull(item.getResponse()); // <1> Exception e = item.getFailure().getFailure(); // <2> - OpenSearchException ee = (OpenSearchException) e; // <3> + BaseOpenSearchException ee = (BaseOpenSearchException) e; // <3> // TODO status is broken! fix in a followup // assertEquals(RestStatus.CONFLICT, ee.status()); // <4> assertThat(e.getMessage(), diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java index a1334062064d2..dc5f1d758356c 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java @@ -32,6 +32,7 @@ package org.opensearch.client.documentation; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.LatchedActionListener; @@ -1925,7 +1926,7 @@ public void testGetAlias() throws Exception { // tag::get-alias-response-error RestStatus status = response.status(); // <1> - OpenSearchException exception = response.getException(); // <2> + BaseOpenSearchException exception = response.getException(); // <2> String error = response.getError(); // <3> // end::get-alias-response-error diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java index bd9cbbdc2f450..91921d1d64821 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java @@ -43,8 +43,8 @@ import org.opensearch.client.RequestOptions; import org.opensearch.client.RestHighLevelClient; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -255,7 +255,7 @@ public void testPutScript() throws Exception { builder.endObject(); } builder.endObject(); - request.content(BytesReference.bytes(builder), XContentType.JSON); // <1> + request.content(BytesReferenceUtil.bytes(builder), XContentType.JSON); // <1> // end::put-stored-script-content-painless // tag::put-stored-script-execute @@ -310,7 +310,7 @@ public void onFailure(Exception e) { builder.endObject(); } builder.endObject(); - request.content(BytesReference.bytes(builder), XContentType.JSON); // <1> + request.content(BytesReferenceUtil.bytes(builder), XContentType.JSON); // <1> // end::put-stored-script-content-mustache client.putScript(request, RequestOptions.DEFAULT); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java index 05479e2e3e81c..90b08a70fd917 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java @@ -32,7 +32,7 @@ package org.opensearch.client.documentation; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.LatchedActionListener; import org.opensearch.action.TaskOperationFailure; @@ -124,7 +124,7 @@ public void testListTasks() throws IOException { // end::list-tasks-response-calc // tag::list-tasks-response-failures - List nodeFailures = response.getNodeFailures(); // <1> + List nodeFailures = response.getNodeFailures(); // <1> List taskFailures = response.getTaskFailures(); // <2> // end::list-tasks-response-failures diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java index 79d4683ae09ae..89e024df4db73 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java @@ -38,6 +38,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -97,7 +98,7 @@ public void testParsingFromOpenSearchResponse() throws IOException { ); esIMD.patterns(Arrays.asList(generateRandomStringArray(32, 4, false, false))); esIMD.settings(randomIndexSettings()); - esIMD.putMapping("_doc", new CompressedXContent(BytesReference.bytes(randomMapping("_doc", xContentType)))); + esIMD.putMapping("_doc", new CompressedXContent(BytesReferenceUtil.bytes(randomMapping("_doc", xContentType)))); int numAliases = randomIntBetween(0, 8); for (int j = 0; j < numAliases; j++) { esIMD.putAlias(randomAliasMetadata(String.format(Locale.ROOT, "%02d ", j) + randomAlphaOfLength(4))); @@ -114,7 +115,7 @@ public void testParsingFromOpenSearchResponse() throws IOException { XContentParser parser = XContentHelper.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(xContentBuilder), + BytesReferenceUtil.bytes(xContentBuilder), xContentType ) ) { diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java index 2a39b0deb8827..85f8f5fc0531f 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java @@ -31,6 +31,7 @@ package org.opensearch.client.tasks; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.TaskOperationFailure; @@ -142,7 +143,7 @@ protected void assertInstances( } // checking failures - List serverNodeFailures = serverTestInstance.getNodeFailures(); + List serverNodeFailures = serverTestInstance.getNodeFailures(); List cNodeFailures = clientInstance.getNodeFailures(); List sExceptionsMessages = serverNodeFailures.stream() .map(x -> org.opensearch.client.tasks.OpenSearchException.buildMessage("exception", x.getMessage(), null)) diff --git a/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java b/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java index 2b282d1fc48c3..a1b65513d3946 100644 --- a/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java +++ b/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java @@ -34,10 +34,13 @@ import com.fasterxml.jackson.core.JsonParseException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.common.compress.NotXContentException; import org.opensearch.core.ParseField; +import org.opensearch.core.common.Strings; import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.rest.RestStatus; import java.io.IOException; import java.io.PrintWriter; @@ -107,7 +110,7 @@ public static String detailedMessage(Throwable t) { if (t.getCause() != null) { StringBuilder sb = new StringBuilder(); while (t != null) { - sb.append(t.getClass().getSimpleName()); + sb.append(getExceptionSimpleClassName(t)); if (t.getMessage() != null) { sb.append("["); sb.append(t.getMessage()); @@ -121,7 +124,7 @@ public static String detailedMessage(Throwable t) { } return sb.toString(); } else { - return t.getClass().getSimpleName() + "[" + t.getMessage() + "]"; + return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; } } @@ -135,7 +138,7 @@ public static String stackTrace(Throwable e) { public static String summaryMessage(Throwable t) { if (t != null) { if (t instanceof BaseOpenSearchException) { - return t.getClass().getSimpleName() + "[" + t.getMessage() + "]"; + return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; } else if (t instanceof IllegalArgumentException) { return "Invalid argument"; } else if (t instanceof JsonParseException) { @@ -224,7 +227,7 @@ public static void generateThrowableXContent(XContentBuilder builder, ToXContent * Returns an underscore case name for the given exception. This method strips {@code OpenSearch} prefixes from exception names. */ public static String getExceptionName(Throwable ex) { - String simpleName = ex.getClass().getSimpleName(); + String simpleName = getExceptionSimpleClassName(ex); if (simpleName.startsWith("OpenSearch")) { simpleName = simpleName.substring("OpenSearch".length()); } @@ -232,6 +235,18 @@ public static String getExceptionName(Throwable ex) { return toUnderscoreCase(simpleName); } + private static String getExceptionSimpleClassName(final Throwable ex) { + String simpleName = ex.getClass().getSimpleName(); + if (Strings.isEmpty(simpleName) && ex instanceof BaseOpenSearchException) { + simpleName = "OpenSearchException"; + } + + if (simpleName.startsWith("BaseOpenSearch")) { + simpleName = simpleName.substring("Base".length()); + } + return simpleName; + } + // lower cases and adds underscores to transitions in a name private static String toUnderscoreCase(String value) { StringBuilder sb = new StringBuilder(); @@ -280,4 +295,21 @@ protected static void headerToXContent(XContentBuilder builder, String key, List } } } + + public static RestStatus status(Throwable t) { + if (t != null) { + if (t instanceof BaseOpenSearchException) { + return ((BaseOpenSearchException) t).status(); + } else if (t instanceof IllegalArgumentException) { + return RestStatus.BAD_REQUEST; + } else if (t instanceof JsonParseException) { + return RestStatus.BAD_REQUEST; + } else if (t instanceof OpenSearchRejectedExecutionException) { + return RestStatus.TOO_MANY_REQUESTS; + } else if (t instanceof NotXContentException) { + return RestStatus.BAD_REQUEST; + } + } + return RestStatus.INTERNAL_SERVER_ERROR; + } } diff --git a/libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java b/libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java index 248673d11797a..944566324e44d 100644 --- a/libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java +++ b/libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java @@ -33,23 +33,36 @@ import org.opensearch.common.CheckedFunction; import org.opensearch.common.Nullable; +import org.opensearch.common.collect.Tuple; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.io.stream.Writeable; import org.opensearch.core.common.Strings; -import org.opensearch.core.common.io.stream.BaseStreamInput; import org.opensearch.core.common.logging.LoggerMessageFormat; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.ToXContentFragment; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParseException; +import org.opensearch.core.xcontent.XContentParser; +import org.opensearch.index.Index; +import org.opensearch.index.shard.ShardId; +import org.opensearch.rest.RestStatus; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import static org.opensearch.BaseOpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; +import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; +import static org.opensearch.common.xcontent.XContentParserUtils.ensureFieldName; + import static java.util.Collections.singletonMap; /** @@ -57,7 +70,7 @@ * * @opensearch.internal */ -public abstract class BaseOpenSearchException extends RuntimeException implements ToXContentFragment { +public abstract class BaseOpenSearchException extends RuntimeException implements Writeable, ToXContentFragment { protected static final String ERROR = "error"; protected static final String ROOT_CAUSE = "root_cause"; @@ -70,6 +83,33 @@ public abstract class BaseOpenSearchException extends RuntimeException implement protected final Map> metadata = new HashMap<>(); protected final Map> headers = new HashMap<>(); + static { + registerExceptionHandle( + new BaseOpenSearchExceptionHandle( + org.opensearch.index.snapshots.IndexShardSnapshotFailedException.class, + org.opensearch.index.snapshots.IndexShardSnapshotFailedException::new, + 0, + UNKNOWN_VERSION_ADDED + ) + ); + registerExceptionHandle( + new BaseOpenSearchExceptionHandle( + org.opensearch.common.ParsingException.class, + org.opensearch.common.ParsingException::new, + 40, + UNKNOWN_VERSION_ADDED + ) + ); + registerExceptionHandle( + new BaseOpenSearchExceptionHandle( + org.opensearch.common.io.stream.NotSerializableExceptionWrapper.class, + org.opensearch.common.io.stream.NotSerializableExceptionWrapper::new, + 62, + UNKNOWN_VERSION_ADDED + ) + ); + } + /** * Construct a BaseOpenSearchException with the specified cause exception. */ @@ -105,6 +145,22 @@ public BaseOpenSearchException(String msg, Throwable cause, Object... args) { super(LoggerMessageFormat.format(msg, args), cause); } + public BaseOpenSearchException(StreamInput in) throws IOException { + this(in.readOptionalString(), in.readException()); + readStackTrace(this, in); + headers.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString)); + metadata.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString)); + } + + @Override + public void writeTo(final StreamOutput out) throws IOException { + out.writeOptionalString(this.getMessage()); + out.writeException(this.getCause()); + writeStackTraces(this, out, StreamOutput::writeException); + out.writeMapOfLists(headers, StreamOutput::writeString, StreamOutput::writeString); + out.writeMapOfLists(metadata, StreamOutput::writeString, StreamOutput::writeString); + } + /** * Render any exception as a xcontent, encapsulated within a field or object named "error". The level of details that are rendered * depends on the value of the "detailed" parameter: when it's false only a simple message based on the type and message of the @@ -393,6 +449,18 @@ private String getIndexUUID() { return null; } + /** + * Returns the rest status code associated with this exception. + */ + public RestStatus status() { + Throwable cause = unwrapCause(); + if (cause == this) { + return RestStatus.INTERNAL_SERVER_ERROR; + } else { + return BaseExceptionsHelper.status(cause); + } + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -440,19 +508,86 @@ private String getShardIdString() { } /** - * An ExceptionHandle for registering Exceptions that can be serialized over the transport wire + * Returns an array of all registered handle IDs. These are the IDs for every registered + * exception. + * + * @return an array of all registered handle IDs + */ + static int[] ids() { + return OpenSearchExceptionHandleRegistry.ids().stream().mapToInt(i -> i).toArray(); + } + + /** + * Returns an array of all registered pairs of handle IDs and exception classes. These pairs are + * provided for every registered exception. + * + * @return an array of all registered pairs of handle IDs and exception classes + */ + @SuppressWarnings("unchecked") + static Tuple>[] classes() { + final Tuple>[] ts = OpenSearchExceptionHandleRegistry.handles() + .stream() + .map(h -> Tuple.tuple(h.id, h.exceptionClass)) + .toArray(Tuple[]::new); + return ts; + } + + public Index getIndex() { + List index = getMetadata(INDEX_METADATA_KEY); + if (index != null && index.isEmpty() == false) { + List index_uuid = getMetadata(INDEX_METADATA_KEY_UUID); + return new Index(index.get(0), index_uuid.get(0)); + } + + return null; + } + + public void setIndex(Index index) { + if (index != null) { + addMetadata(INDEX_METADATA_KEY, index.getName()); + addMetadata(INDEX_METADATA_KEY_UUID, index.getUUID()); + } + } + + public void setIndex(String index) { + if (index != null) { + setIndex(new Index(index, Strings.UNKNOWN_UUID_VALUE)); + } + } + + public ShardId getShardId() { + List shard = getMetadata(SHARD_METADATA_KEY); + if (shard != null && shard.isEmpty() == false) { + return new ShardId(getIndex(), Integer.parseInt(shard.get(0))); + } + return null; + } + + public void setShard(ShardId shardId) { + if (shardId != null) { + setIndex(shardId.getIndex()); + addMetadata(SHARD_METADATA_KEY, Integer.toString(shardId.id())); + } + } + + /** + * This is the list of Exceptions OpenSearch can throw over the wire or save into a corruption marker. Each value in the enum is a + * single exception tying the Class to an id for use of the encode side and the id back to a constructor for use on the decode side. As + * such its ok if the exceptions to change names so long as their constructor can still read the exception. Each exception is listed + * in id order. If you want to remove an exception leave a tombstone comment and mark the id as null in + * ExceptionSerializationTests.testIds.ids. * * @opensearch.internal */ - protected static abstract class BaseOpenSearchExceptionHandle { + protected static class BaseOpenSearchExceptionHandle { final Class exceptionClass; - final CheckedFunction constructor; + final CheckedFunction constructor; final int id; final Version versionAdded; - BaseOpenSearchExceptionHandle( + BaseOpenSearchExceptionHandle( Class exceptionClass, - CheckedFunction constructor, + CheckedFunction constructor, int id, Version versionAdded ) { @@ -465,7 +600,7 @@ BaseOpenSearchExc } @SuppressWarnings("unchecked") - public static BaseOpenSearchException readException(T input, int id) throws IOException { + public static BaseOpenSearchException readException(T input, int id) throws IOException { CheckedFunction opensearchException = (CheckedFunction< T, ? extends BaseOpenSearchException, @@ -476,6 +611,207 @@ public static BaseOpenSearchException readException( return opensearchException.apply(input); } + /** + * Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and + * adds it to the given exception. + */ + public static T readStackTrace(T throwable, StreamInput in) throws IOException { + throwable.setStackTrace(in.readArray(i -> { + final String declaringClasss = i.readString(); + final String fileName = i.readOptionalString(); + final String methodName = i.readString(); + final int lineNumber = i.readVInt(); + return new StackTraceElement(declaringClasss, methodName, fileName, lineNumber); + }, StackTraceElement[]::new)); + + int numSuppressed = in.readVInt(); + for (int i = 0; i < numSuppressed; i++) { + throwable.addSuppressed(in.readException()); + } + return throwable; + } + + /** + * Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream. + */ + public static T writeStackTraces( + T throwable, + StreamOutput out, + Writer exceptionWriter + ) throws IOException { + out.writeArray((o, v) -> { + o.writeString(v.getClassName()); + o.writeOptionalString(v.getFileName()); + o.writeString(v.getMethodName()); + o.writeVInt(v.getLineNumber()); + }, throwable.getStackTrace()); + out.writeArray(exceptionWriter, throwable.getSuppressed()); + return throwable; + } + + /** + * Returns the serialization id the given exception. + */ + public static int getId(final Class exception) { + return OpenSearchExceptionHandleRegistry.getId(exception); + } + + /** + * Returns true iff the given class is a registered for an exception to be read. + */ + public static boolean isRegistered(final Class exception, Version version) { + return OpenSearchExceptionHandleRegistry.isRegistered(exception, version); + } + + /** + * Generate a {@link BaseOpenSearchException} from a {@link XContentParser}. This does not + * return the original exception type (ie NodeClosedException for example) but just wraps + * the type, the reason and the cause of the exception. It also recursively parses the + * tree structure of the cause, returning it as a tree structure of {@link BaseOpenSearchException} + * instances. + */ + public static BaseOpenSearchException fromXContent(XContentParser parser) throws IOException { + XContentParser.Token token = parser.nextToken(); + ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); + return innerFromXContent(parser, false); + } + + /** + * Parses the output of {@link #generateFailureXContent(XContentBuilder, Params, Exception, boolean)} + */ + public static BaseOpenSearchException failureFromXContent(XContentParser parser) throws IOException { + XContentParser.Token token = parser.currentToken(); + ensureFieldName(parser, token, ERROR); + + token = parser.nextToken(); + if (token.isValue()) { + return new BaseOpenSearchException(buildMessage("exception", parser.text(), null)) { + }; + } + + ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); + token = parser.nextToken(); + + // Root causes are parsed in the innerFromXContent() and are added as suppressed exceptions. + return innerFromXContent(parser, true); + } + + public static BaseOpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException { + XContentParser.Token token = parser.currentToken(); + ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); + + String type = null, reason = null, stack = null; + BaseOpenSearchException cause = null; + Map> metadata = new HashMap<>(); + Map> headers = new HashMap<>(); + List rootCauses = new ArrayList<>(); + List suppressed = new ArrayList<>(); + + for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) { + String currentFieldName = parser.currentName(); + token = parser.nextToken(); + + if (token.isValue()) { + if (BaseExceptionsHelper.TYPE.equals(currentFieldName)) { + type = parser.text(); + } else if (BaseExceptionsHelper.REASON.equals(currentFieldName)) { + reason = parser.text(); + } else if (BaseExceptionsHelper.STACK_TRACE.equals(currentFieldName)) { + stack = parser.text(); + } else if (token == XContentParser.Token.VALUE_STRING) { + metadata.put(currentFieldName, Collections.singletonList(parser.text())); + } + } else if (token == XContentParser.Token.START_OBJECT) { + if (BaseExceptionsHelper.CAUSED_BY.equals(currentFieldName)) { + cause = fromXContent(parser); + } else if (BaseExceptionsHelper.HEADER.equals(currentFieldName)) { + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + currentFieldName = parser.currentName(); + } else { + List values = headers.getOrDefault(currentFieldName, new ArrayList<>()); + if (token == XContentParser.Token.VALUE_STRING) { + values.add(parser.text()); + } else if (token == XContentParser.Token.START_ARRAY) { + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + if (token == XContentParser.Token.VALUE_STRING) { + values.add(parser.text()); + } else { + parser.skipChildren(); + } + } + } else if (token == XContentParser.Token.START_OBJECT) { + parser.skipChildren(); + } + headers.put(currentFieldName, values); + } + } + } else { + // Any additional metadata object added by the metadataToXContent method is ignored + // and skipped, so that the parser does not fail on unknown fields. The parser only + // support metadata key-pairs and metadata arrays of values. + parser.skipChildren(); + } + } else if (token == XContentParser.Token.START_ARRAY) { + if (parseRootCauses && ROOT_CAUSE.equals(currentFieldName)) { + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + rootCauses.add(fromXContent(parser)); + } + } else if (BaseExceptionsHelper.SUPPRESSED.match(currentFieldName, parser.getDeprecationHandler())) { + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + suppressed.add(fromXContent(parser)); + } + } else { + // Parse the array and add each item to the corresponding list of metadata. + // Arrays of objects are not supported yet and just ignored and skipped. + List values = new ArrayList<>(); + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + if (token == XContentParser.Token.VALUE_STRING) { + values.add(parser.text()); + } else { + parser.skipChildren(); + } + } + if (values.size() > 0) { + if (metadata.containsKey(currentFieldName)) { + values.addAll(metadata.get(currentFieldName)); + } + metadata.put(currentFieldName, values); + } + } + } + } + + BaseOpenSearchException e = new BaseOpenSearchException(buildMessage(type, reason, stack), cause) { + }; + for (Map.Entry> entry : metadata.entrySet()) { + // subclasses can print out additional metadata through the metadataToXContent method. Simple key-value pairs will be + // parsed back and become part of this metadata set, while objects and arrays are not supported when parsing back. + // Those key-value pairs become part of the metadata set and inherit the "opensearch." prefix as that is currently required + // by addMetadata. The prefix will get stripped out when printing metadata out so it will be effectively invisible. + // TODO move subclasses that print out simple metadata to using addMetadata directly and support also numbers and booleans. + // TODO rename metadataToXContent and have only SearchPhaseExecutionException use it, which prints out complex objects + e.addMetadata(BaseExceptionsHelper.OPENSEARCH_PREFIX_KEY + entry.getKey(), entry.getValue()); + } + for (Map.Entry> header : headers.entrySet()) { + e.addHeader(header.getKey(), header.getValue()); + } + + // Adds root causes as suppressed exception. This way they are not lost + // after parsing and can be retrieved using getSuppressed() method. + for (BaseOpenSearchException rootCause : rootCauses) { + e.addSuppressed(rootCause); + } + for (BaseOpenSearchException s : suppressed) { + e.addSuppressed(s); + } + return e; + } + + static Set> getRegisteredKeys() { // for testing + return OpenSearchExceptionHandleRegistry.getRegisteredKeys(); + } + /** * Registry of ExceptionHandlers * @@ -485,7 +821,7 @@ public static class OpenSearchExceptionHandleRegistry { /** Registry mapping from unique Ordinal to the Exception Constructor */ private static final Map< Integer, - CheckedFunction> ID_TO_SUPPLIER_REGISTRY = + CheckedFunction> ID_TO_SUPPLIER_REGISTRY = new ConcurrentHashMap<>(); /** Registry mapping from Exception class to the Exception Handler */ private static final Map< @@ -493,7 +829,7 @@ public static class OpenSearchExceptionHandleRegistry { BaseOpenSearchExceptionHandle> CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY = new ConcurrentHashMap<>(); /** returns the Exception constructor function from a given ordinal */ - public static CheckedFunction getSupplier(final int id) { + public static CheckedFunction getSupplier(final int id) { return ID_TO_SUPPLIER_REGISTRY.get(id); } diff --git a/server/src/main/java/org/opensearch/action/ShardOperationFailedException.java b/libs/core/src/main/java/org/opensearch/action/ShardOperationFailedException.java similarity index 100% rename from server/src/main/java/org/opensearch/action/ShardOperationFailedException.java rename to libs/core/src/main/java/org/opensearch/action/ShardOperationFailedException.java diff --git a/server/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java similarity index 91% rename from server/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java rename to libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java index 35334cbbad801..6608d61ebf8a7 100644 --- a/server/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java +++ b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java @@ -33,8 +33,8 @@ package org.opensearch.action.support; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.OpenSearchException; -import org.opensearch.ExceptionsHelper; +import org.opensearch.BaseOpenSearchException; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -47,7 +47,7 @@ import java.io.IOException; -import static org.opensearch.ExceptionsHelper.detailedMessage; +import static org.opensearch.BaseExceptionsHelper.detailedMessage; import static org.opensearch.core.xcontent.ConstructingObjectParser.constructorArg; /** @@ -70,7 +70,7 @@ public class DefaultShardOperationFailedException extends ShardOperationFailedEx protected static void declareFields(ConstructingObjectParser objectParser) { objectParser.declareString(constructorArg(), new ParseField(INDEX)); objectParser.declareInt(constructorArg(), new ParseField(SHARD_ID)); - objectParser.declareObject(constructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField(REASON)); + objectParser.declareObject(constructorArg(), (p, c) -> BaseOpenSearchException.fromXContent(p), new ParseField(REASON)); } static { @@ -83,7 +83,7 @@ protected DefaultShardOperationFailedException(StreamInput in) throws IOExceptio readFrom(in, this); } - public DefaultShardOperationFailedException(OpenSearchException e) { + public DefaultShardOperationFailedException(BaseOpenSearchException e) { super( e.getIndex() == null ? null : e.getIndex().getName(), e.getShardId() == null ? -1 : e.getShardId().getId(), @@ -94,7 +94,7 @@ public DefaultShardOperationFailedException(OpenSearchException e) { } public DefaultShardOperationFailedException(String index, int shardId, Throwable cause) { - super(index, shardId, detailedMessage(cause), ExceptionsHelper.status(cause), cause); + super(index, shardId, BaseExceptionsHelper.detailedMessage(cause), BaseExceptionsHelper.status(cause), cause); } public static DefaultShardOperationFailedException readShardOperationFailed(StreamInput in) throws IOException { diff --git a/server/src/main/java/org/opensearch/common/ParsingException.java b/libs/core/src/main/java/org/opensearch/common/ParsingException.java similarity index 93% rename from server/src/main/java/org/opensearch/common/ParsingException.java rename to libs/core/src/main/java/org/opensearch/common/ParsingException.java index 5a9e99f5987d9..c2a8c1ce8230f 100644 --- a/server/src/main/java/org/opensearch/common/ParsingException.java +++ b/libs/core/src/main/java/org/opensearch/common/ParsingException.java @@ -32,9 +32,10 @@ package org.opensearch.common; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentLocation; import org.opensearch.core.xcontent.XContentParser; @@ -49,7 +50,7 @@ * * @opensearch.internal */ -public class ParsingException extends OpenSearchException { +public class ParsingException extends BaseOpenSearchException { protected static final int UNKNOWN_POSITION = -1; private final int lineNumber; @@ -111,7 +112,7 @@ public RestStatus status() { } @Override - protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException { + protected void metadataToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { if (lineNumber != UNKNOWN_POSITION) { builder.field("line", lineNumber); builder.field("col", columnNumber); diff --git a/server/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java b/libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java similarity index 99% rename from server/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java rename to libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java index 7b3c71321e4f0..030c3ce03bec0 100644 --- a/server/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java +++ b/libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java @@ -313,7 +313,7 @@ public int available() { } @Override - protected void ensureCanReadBytes(int bytesToRead) throws EOFException { + public void ensureCanReadBytes(int bytesToRead) throws EOFException { int bytesAvailable = length() - offset(); if (bytesAvailable < bytesToRead) { throw new EOFException("tried to read: " + bytesToRead + " bytes but only " + bytesAvailable + " remaining"); diff --git a/server/src/main/java/org/opensearch/common/bytes/BytesArray.java b/libs/core/src/main/java/org/opensearch/common/bytes/BytesArray.java similarity index 100% rename from server/src/main/java/org/opensearch/common/bytes/BytesArray.java rename to libs/core/src/main/java/org/opensearch/common/bytes/BytesArray.java diff --git a/server/src/main/java/org/opensearch/common/bytes/BytesReference.java b/libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java similarity index 90% rename from server/src/main/java/org/opensearch/common/bytes/BytesReference.java rename to libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java index 5bafd24e1e928..41e6044a67eea 100644 --- a/server/src/main/java/org/opensearch/common/bytes/BytesReference.java +++ b/libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java @@ -35,13 +35,10 @@ import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefIterator; -import org.opensearch.common.io.stream.BytesStream; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.util.ByteArray; import org.opensearch.core.xcontent.ToXContentFragment; -import org.opensearch.core.xcontent.XContentBuilder; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; @@ -54,20 +51,6 @@ */ public interface BytesReference extends Comparable, ToXContentFragment { - /** - * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder, - * so no further fields may be added. - */ - static BytesReference bytes(XContentBuilder xContentBuilder) { - xContentBuilder.close(); - OutputStream stream = xContentBuilder.getOutputStream(); - if (stream instanceof ByteArrayOutputStream) { - return new BytesArray(((ByteArrayOutputStream) stream).toByteArray()); - } else { - return ((BytesStream) stream).bytes(); - } - } - /** * Returns a compact array from the given BytesReference. The returned array won't be copied unless necessary. If you need * to modify the returned array use {@code BytesRef.deepCopyOf(reference.toBytesRef()} instead diff --git a/server/src/main/java/org/opensearch/common/bytes/CompositeBytesReference.java b/libs/core/src/main/java/org/opensearch/common/bytes/CompositeBytesReference.java similarity index 100% rename from server/src/main/java/org/opensearch/common/bytes/CompositeBytesReference.java rename to libs/core/src/main/java/org/opensearch/common/bytes/CompositeBytesReference.java diff --git a/server/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java b/libs/core/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java similarity index 94% rename from server/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java rename to libs/core/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java index b7439853f11ba..9d432bc6fdd8c 100644 --- a/server/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java +++ b/libs/core/src/main/java/org/opensearch/common/bytes/PagedBytesReference.java @@ -35,7 +35,6 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefIterator; import org.opensearch.common.util.ByteArray; -import org.opensearch.common.util.PageCacheRecycler; import java.io.IOException; @@ -47,7 +46,7 @@ */ public class PagedBytesReference extends AbstractBytesReference { - private static final int PAGE_SIZE = PageCacheRecycler.BYTE_PAGE_SIZE; + public static final int PAGE_SIZE_IN_BYTES = 1 << 14; private final ByteArray byteArray; private final int offset; @@ -95,7 +94,7 @@ public final BytesRefIterator iterator() { // we calculate the initial fragment size here to ensure that if this reference is a slice we are still page aligned // across the entire iteration. The first page is smaller if our offset != 0 then we start in the middle of the page // otherwise we iterate full pages until we reach the last chunk which also might end within a page. - final int initialFragmentSize = offset != 0 ? PAGE_SIZE - (offset % PAGE_SIZE) : PAGE_SIZE; + final int initialFragmentSize = offset != 0 ? PAGE_SIZE_IN_BYTES - (offset % PAGE_SIZE_IN_BYTES) : PAGE_SIZE_IN_BYTES; return new BytesRefIterator() { int position = 0; int nextFragmentSize = Math.min(length, initialFragmentSize); @@ -109,7 +108,7 @@ public BytesRef next() throws IOException { assert materialized == false : "iteration should be page aligned but array got materialized"; position += nextFragmentSize; final int remaining = length - position; - nextFragmentSize = Math.min(remaining, PAGE_SIZE); + nextFragmentSize = Math.min(remaining, PAGE_SIZE_IN_BYTES); return slice; } else { assert nextFragmentSize == 0 : "fragmentSize expected [0] but was: [" + nextFragmentSize + "]"; diff --git a/server/src/main/java/org/opensearch/common/compress/NotXContentException.java b/libs/core/src/main/java/org/opensearch/common/compress/NotXContentException.java similarity index 100% rename from server/src/main/java/org/opensearch/common/compress/NotXContentException.java rename to libs/core/src/main/java/org/opensearch/common/compress/NotXContentException.java diff --git a/server/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java similarity index 95% rename from server/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java index 991fd0fc09a9d..37c3081d19c75 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java @@ -32,7 +32,7 @@ package org.opensearch.common.io.stream; -import org.opensearch.common.io.Streams; +import org.opensearch.core.common.io.StreamsUtil; import java.io.EOFException; import java.io.IOException; @@ -80,7 +80,7 @@ public byte readByte() throws IOException { @Override public void readBytes(byte[] b, int offset, int len) throws IOException { if (len < 0) throw new IndexOutOfBoundsException(); - final int read = Streams.readFully(is, b, offset, len); + final int read = StreamsUtil.readFully(is, b, offset, len); if (read != len) { throw new EOFException(); } @@ -132,7 +132,7 @@ public long skip(long n) throws IOException { } @Override - protected void ensureCanReadBytes(int length) throws EOFException { + public void ensureCanReadBytes(int length) throws EOFException { if (length > sizeLimit) { throw new EOFException("tried to read: " + length + " bytes but this stream is limited to: " + sizeLimit); } diff --git a/server/src/main/java/org/opensearch/common/io/stream/NamedWriteable.java b/libs/core/src/main/java/org/opensearch/common/io/stream/NamedWriteable.java similarity index 100% rename from server/src/main/java/org/opensearch/common/io/stream/NamedWriteable.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/NamedWriteable.java diff --git a/server/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java b/libs/core/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java similarity index 99% rename from server/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java index 0240d0a0a8bb3..985b2ad113f22 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/NamedWriteableRegistry.java @@ -92,6 +92,7 @@ public NamedWriteableRegistry(List entries) { Map, Map>> registry = new HashMap<>(); Map> readers = null; + @SuppressWarnings("rawtypes") Class currentCategory = null; for (Entry entry : entries) { if (currentCategory != entry.categoryClass) { diff --git a/server/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java b/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java similarity index 89% rename from server/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java index 636df65b8c319..3dd4b9e66fe9f 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java @@ -33,8 +33,7 @@ package org.opensearch.common.io.stream; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.OpenSearchException; -import org.opensearch.ExceptionsHelper; +import org.opensearch.BaseOpenSearchException; import org.opensearch.rest.RestStatus; import java.io.IOException; @@ -48,7 +47,7 @@ * * @opensearch.internal */ -public final class NotSerializableExceptionWrapper extends OpenSearchException { +public final class NotSerializableExceptionWrapper extends BaseOpenSearchException { private final String name; private final RestStatus status; @@ -56,13 +55,13 @@ public final class NotSerializableExceptionWrapper extends OpenSearchException { public NotSerializableExceptionWrapper(Throwable other) { super(BaseExceptionsHelper.getExceptionName(other) + ": " + other.getMessage(), other.getCause()); this.name = BaseExceptionsHelper.getExceptionName(other); - this.status = ExceptionsHelper.status(other); + this.status = BaseExceptionsHelper.status(other); setStackTrace(other.getStackTrace()); for (Throwable otherSuppressed : other.getSuppressed()) { addSuppressed(otherSuppressed); } - if (other instanceof OpenSearchException) { - OpenSearchException ex = (OpenSearchException) other; + if (other instanceof BaseOpenSearchException) { + BaseOpenSearchException ex = (BaseOpenSearchException) other; for (String key : ex.getHeaderKeys()) { this.addHeader(key, ex.getHeader(key)); } diff --git a/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java similarity index 74% rename from server/src/main/java/org/opensearch/common/io/stream/StreamInput.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java index 7e0ef07c7e602..c3af941cd4418 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java @@ -37,10 +37,12 @@ import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.CharsRef; +import org.opensearch.BaseOpenSearchException; import org.opensearch.Build; -import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.common.CharArrays; import org.opensearch.common.Nullable; @@ -50,8 +52,6 @@ import org.opensearch.common.text.Text; import org.opensearch.common.unit.TimeValue; import org.opensearch.core.common.Strings; -import org.opensearch.core.common.io.stream.BaseStreamInput; -import org.opensearch.core.common.io.stream.BaseWriteable; import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import java.io.ByteArrayInputStream; @@ -59,6 +59,7 @@ import java.io.FileNotFoundException; import java.io.FilterInputStream; import java.io.IOException; +import java.io.InputStream; import java.math.BigInteger; import java.nio.file.AccessDeniedException; import java.nio.file.AtomicMoveNotSupportedException; @@ -82,12 +83,13 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.IntFunction; -import static org.opensearch.OpenSearchException.readStackTrace; +import static org.opensearch.BaseOpenSearchException.readStackTrace; /** * A stream from this node to another node. Technically, it can also be streamed to a byte array but that is mostly for testing. @@ -102,7 +104,37 @@ * * @opensearch.internal */ -public abstract class StreamInput extends BaseStreamInput { +public abstract class StreamInput extends InputStream { + + private Version version = Version.CURRENT; + + /** + * The version of the node on the other side of this stream. + */ + public Version getVersion() { + return this.version; + } + + /** + * Set the version of the node on the other side of this stream. + */ + public void setVersion(Version version) { + this.version = version; + } + + /** + * Reads and returns a single byte. + */ + public abstract byte readByte() throws IOException; + + /** + * Reads a specified number of bytes into an array at the specified offset. + * + * @param b the array to read bytes into + * @param offset the offset in the array to start storing bytes + * @param len the number of bytes to read + */ + public abstract void readBytes(byte[] b, int offset, int len) throws IOException; /** * Reads a bytes reference from this stream, might hold an actual reference to the underlying @@ -145,6 +177,10 @@ public BytesRef readBytesRef() throws IOException { return readBytesRef(length); } + public void readFully(byte[] b) throws IOException { + readBytes(b, 0, b.length); + } + public BytesRef readBytesRef(int length) throws IOException { if (length == 0) { return new BytesRef(); @@ -158,6 +194,47 @@ public short readShort() throws IOException { return (short) (((readByte() & 0xFF) << 8) | (readByte() & 0xFF)); } + /** + * Reads four bytes and returns an int. + */ + public int readInt() throws IOException { + return ((readByte() & 0xFF) << 24) | ((readByte() & 0xFF) << 16) | ((readByte() & 0xFF) << 8) | (readByte() & 0xFF); + } + + /** + * Reads an int stored in variable-length format. Reads between one and + * five bytes. Smaller values take fewer bytes. Negative numbers + * will always use all 5 bytes and are therefore better serialized + * using {@link #readInt} + */ + public int readVInt() throws IOException { + byte b = readByte(); + int i = b & 0x7F; + if ((b & 0x80) == 0) { + return i; + } + b = readByte(); + i |= (b & 0x7F) << 7; + if ((b & 0x80) == 0) { + return i; + } + b = readByte(); + i |= (b & 0x7F) << 14; + if ((b & 0x80) == 0) { + return i; + } + b = readByte(); + i |= (b & 0x7F) << 21; + if ((b & 0x80) == 0) { + return i; + } + b = readByte(); + if ((b & 0x80) != 0) { + throw new IOException("Invalid vInt ((" + Integer.toHexString(b) + " & 0x7f) << 28) | " + Integer.toHexString(i)); + } + return i | ((b & 0x7F) << 28); + } + /** * Reads an optional {@link Integer}. */ @@ -282,6 +359,14 @@ public Text readText() throws IOException { return new Text(readBytesReference(length)); } + @Nullable + public String readOptionalString() throws IOException { + if (readBoolean()) { + return readString(); + } + return null; + } + @Nullable public SecureString readOptionalSecureString() throws IOException { SecureString value = null; @@ -305,6 +390,157 @@ public Float readOptionalFloat() throws IOException { return null; } + @Nullable + public Integer readOptionalVInt() throws IOException { + if (readBoolean()) { + return readVInt(); + } + return null; + } + + // Maximum char-count to de-serialize via the thread-local CharsRef buffer + private static final int SMALL_STRING_LIMIT = 1024; + + // Reusable bytes for deserializing strings + private static final ThreadLocal stringReadBuffer = ThreadLocal.withInitial(() -> new byte[1024]); + + // Thread-local buffer for smaller strings + private static final ThreadLocal smallSpare = ThreadLocal.withInitial(() -> new CharsRef(SMALL_STRING_LIMIT)); + + // Larger buffer used for long strings that can't fit into the thread-local buffer + // We don't use a CharsRefBuilder since we exactly know the size of the character array up front + // this prevents calling grow for every character since we don't need this + private CharsRef largeSpare; + + public String readString() throws IOException { + final int charCount = readArraySize(); + final CharsRef charsRef; + if (charCount > SMALL_STRING_LIMIT) { + if (largeSpare == null) { + largeSpare = new CharsRef(ArrayUtil.oversize(charCount, Character.BYTES)); + } else if (largeSpare.chars.length < charCount) { + // we don't use ArrayUtils.grow since there is no need to copy the array + largeSpare.chars = new char[ArrayUtil.oversize(charCount, Character.BYTES)]; + } + charsRef = largeSpare; + } else { + charsRef = smallSpare.get(); + } + charsRef.length = charCount; + int charsOffset = 0; + int offsetByteArray = 0; + int sizeByteArray = 0; + int missingFromPartial = 0; + final byte[] byteBuffer = stringReadBuffer.get(); + final char[] charBuffer = charsRef.chars; + for (; charsOffset < charCount;) { + final int charsLeft = charCount - charsOffset; + int bufferFree = byteBuffer.length - sizeByteArray; + // Determine the minimum amount of bytes that are left in the string + final int minRemainingBytes; + if (missingFromPartial > 0) { + // One byte for each remaining char except for the already partially read char + minRemainingBytes = missingFromPartial + charsLeft - 1; + missingFromPartial = 0; + } else { + // Each char has at least a single byte + minRemainingBytes = charsLeft; + } + final int toRead; + if (bufferFree < minRemainingBytes) { + // We don't have enough space left in the byte array to read as much as we'd like to so we free up as many bytes in the + // buffer by moving unused bytes that didn't make up a full char in the last iteration to the beginning of the buffer, + // if there are any + if (offsetByteArray > 0) { + sizeByteArray = sizeByteArray - offsetByteArray; + switch (sizeByteArray) { // We only have 0, 1 or 2 => no need to bother with a native call to System#arrayCopy + case 1: + byteBuffer[0] = byteBuffer[offsetByteArray]; + break; + case 2: + byteBuffer[0] = byteBuffer[offsetByteArray]; + byteBuffer[1] = byteBuffer[offsetByteArray + 1]; + break; + } + assert sizeByteArray <= 2 : "We never copy more than 2 bytes here since a char is 3 bytes max"; + toRead = Math.min(bufferFree + offsetByteArray, minRemainingBytes); + offsetByteArray = 0; + } else { + toRead = bufferFree; + } + } else { + toRead = minRemainingBytes; + } + readBytes(byteBuffer, sizeByteArray, toRead); + sizeByteArray += toRead; + // As long as we at least have three bytes buffered we don't need to do any bounds checking when getting the next char since we + // read 3 bytes per char/iteration at most + for (; offsetByteArray < sizeByteArray - 2; offsetByteArray++) { + final int c = byteBuffer[offsetByteArray] & 0xff; + switch (c >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + charBuffer[charsOffset++] = (char) c; + break; + case 12: + case 13: + charBuffer[charsOffset++] = (char) ((c & 0x1F) << 6 | byteBuffer[++offsetByteArray] & 0x3F); + break; + case 14: + charBuffer[charsOffset++] = (char) ((c & 0x0F) << 12 | (byteBuffer[++offsetByteArray] & 0x3F) << 6 + | (byteBuffer[++offsetByteArray] & 0x3F)); + break; + default: + throwOnBrokenChar(c); + } + } + // try to extract chars from remaining bytes with bounds checks for multi-byte chars + final int bufferedBytesRemaining = sizeByteArray - offsetByteArray; + for (int i = 0; i < bufferedBytesRemaining; i++) { + final int c = byteBuffer[offsetByteArray] & 0xff; + switch (c >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + charBuffer[charsOffset++] = (char) c; + offsetByteArray++; + break; + case 12: + case 13: + missingFromPartial = 2 - (bufferedBytesRemaining - i); + if (missingFromPartial == 0) { + offsetByteArray++; + charBuffer[charsOffset++] = (char) ((c & 0x1F) << 6 | byteBuffer[offsetByteArray++] & 0x3F); + } + ++i; + break; + case 14: + missingFromPartial = 3 - (bufferedBytesRemaining - i); + ++i; + break; + default: + throwOnBrokenChar(c); + } + } + } + return charsRef.toString(); + } + + private static void throwOnBrokenChar(int c) throws IOException { + throw new IOException("Invalid string; unexpected character: " + c + " hex: " + Integer.toHexString(c)); + } + public SecureString readSecureString() throws IOException { BytesReference bytesRef = readBytesReference(); byte[] bytes = BytesReference.toBytes(bytesRef); @@ -331,6 +567,43 @@ public final Double readOptionalDouble() throws IOException { return null; } + /** + * Reads a boolean. + */ + public final boolean readBoolean() throws IOException { + return readBoolean(readByte()); + } + + private boolean readBoolean(final byte value) { + if (value == 0) { + return false; + } else if (value == 1) { + return true; + } else { + final String message = String.format(Locale.ROOT, "unexpected byte [0x%02x]", value); + throw new IllegalStateException(message); + } + } + + @Nullable + public final Boolean readOptionalBoolean() throws IOException { + final byte value = readByte(); + if (value == 2) { + return null; + } else { + return readBoolean(value); + } + } + + /** + * Closes the stream to further operations. + */ + @Override + public abstract void close() throws IOException; + + @Override + public abstract int available() throws IOException; + public String[] readStringArray() throws IOException { int size = readArraySize(); if (size == 0) { @@ -409,7 +682,7 @@ public Map readMap() throws IOException { @Nullable public Object readGenericValue() throws IOException { byte type = readByte(); - BaseWriteable.Reader r = BaseWriteable.WriteableRegistry.getReader(type); + Writeable.Reader r = Writeable.WriteableRegistry.getReader(type); if (r != null) { return r.read(this); } @@ -489,7 +762,7 @@ public final Instant readOptionalInstant() throws IOException { return present ? readInstant() : null; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) private List readArrayList() throws IOException { int size = readArraySize(); if (size == 0) { @@ -521,6 +794,7 @@ private Object[] readArray() throws IOException { return list8; } + @SuppressWarnings({ "rawtypes", "unchecked" }) private Map readLinkedHashMap() throws IOException { int size9 = readArraySize(); if (size9 == 0) { @@ -533,6 +807,7 @@ private Map readLinkedHashMap() throws IOException { return map9; } + @SuppressWarnings({ "rawtypes", "unchecked" }) private Map readHashMap() throws IOException { int size10 = readArraySize(); if (size10 == 0) { @@ -706,7 +981,7 @@ public T readException() throws IOException { switch (key) { case 0: final int ord = readVInt(); - return (T) OpenSearchException.readException(this, ord); + return (T) BaseOpenSearchException.readException(this, ord); case 1: String msg1 = readOptionalString(); String resource1 = readOptionalString(); @@ -873,7 +1148,7 @@ public C readOptionalNamedWriteable(Class category * @return the list of objects * @throws IOException if an I/O exception occurs reading the list */ - public List readList(final BaseWriteable.Reader reader) throws IOException { + public List readList(final Writeable.Reader reader) throws IOException { return readCollection(reader, ArrayList::new, Collections.emptyList()); } @@ -912,6 +1187,22 @@ public Set readSet(Writeable.Reader reader) throws IOException { return readCollection(reader, HashSet::new, Collections.emptySet()); } + /** + * Reads a collection of objects + */ + private > C readCollection(Writeable.Reader reader, IntFunction constructor, C empty) + throws IOException { + int count = readArraySize(); + if (count == 0) { + return empty; + } + C builder = constructor.apply(count); + for (int i = 0; i < count; i++) { + builder.add(reader.read(this)); + } + return builder; + } + /** * Reads a list of {@link NamedWriteable}s. If the returned list contains any entries it will be mutable. * If it is empty it might be immutable. @@ -967,12 +1258,30 @@ public static StreamInput wrap(byte[] bytes, int offset, int length) { return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length), length); } + /** + * Reads a vint via {@link #readVInt()} and applies basic checks to ensure the read array size is sane. + * This method uses {@link #ensureCanReadBytes(int)} to ensure this stream has enough bytes to read for the read array size. + */ + private int readArraySize() throws IOException { + final int arraySize = readVInt(); + if (arraySize > ArrayUtil.MAX_ARRAY_LENGTH) { + throw new IllegalStateException("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: " + arraySize); + } + if (arraySize < 0) { + throw new NegativeArraySizeException("array size must be positive but was: " + arraySize); + } + // lets do a sanity check that if we are reading an array size that is bigger that the remaining bytes we can safely + // throw an exception instead of allocating the array based on the size. A simple corrutpted byte can make a node go OOM + // if the size is large and for perf reasons we allocate arrays ahead of time + ensureCanReadBytes(arraySize); + return arraySize; + } + /** * This method throws an {@link EOFException} if the given number of bytes can not be read from the this stream. This method might * be a no-op depending on the underlying implementation if the information of the remaining bytes is not present. */ - @Override - protected abstract void ensureCanReadBytes(int length) throws EOFException; + public abstract void ensureCanReadBytes(int length) throws EOFException; private static final TimeUnit[] TIME_UNITS = TimeUnit.values(); diff --git a/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java similarity index 88% rename from server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java index 8911e90aa7511..c69fe6e93f550 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java @@ -40,26 +40,24 @@ import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; +import org.opensearch.BaseOpenSearchException; import org.opensearch.Build; -import org.opensearch.OpenSearchException; import org.opensearch.Version; -import org.opensearch.cluster.ClusterState; -import org.opensearch.cluster.metadata.Metadata; import org.opensearch.common.CharArrays; import org.opensearch.common.Nullable; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.io.stream.Writeable.WriteableRegistry; import org.opensearch.common.io.stream.Writeable.Writer; import org.opensearch.common.settings.SecureString; import org.opensearch.common.text.Text; import org.opensearch.common.unit.TimeValue; -import org.opensearch.core.common.io.stream.BaseStreamOutput; -import org.opensearch.core.common.io.stream.BaseWriteable; import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.OutputStream; import java.math.BigInteger; import java.nio.file.AccessDeniedException; import java.nio.file.AtomicMoveNotSupportedException; @@ -100,15 +98,30 @@ * * @opensearch.internal */ -public abstract class StreamOutput extends BaseStreamOutput { +public abstract class StreamOutput extends OutputStream { private static final int MAX_NESTED_EXCEPTION_LEVEL = 100; + private Version version = Version.CURRENT; private Set features = Collections.emptySet(); /** - * Test if the stream has the specified feature. Features are used when serializing {@link ClusterState.Custom} or - * {@link Metadata.Custom}; see also {@link ClusterState.FeatureAware}. + * The version of the node on the other side of this stream. + */ + public Version getVersion() { + return this.version; + } + + /** + * Set the version of the node on the other side of this stream. + */ + public void setVersion(Version version) { + this.version = version; + } + + /** + * Test if the stream has the specified feature. Features are used when serializing {@code ClusterState.Custom} or + * {@code Metadata.Custom}; see also {@code ClusterState.FeatureAware}. * * @param feature the feature to test * @return true if the stream has the specified feature @@ -139,6 +152,11 @@ public void seek(long position) throws IOException { throw new UnsupportedOperationException(); } + /** + * Writes a single byte. + */ + public abstract void writeByte(byte b) throws IOException; + /** * Writes an array of bytes. * @@ -158,6 +176,15 @@ public void writeBytes(byte[] b, int length) throws IOException { writeBytes(b, 0, length); } + /** + * Writes an array of bytes. + * + * @param b the bytes to write + * @param offset the offset in the byte array + * @param length the number of bytes to write + */ + public abstract void writeBytes(byte[] b, int offset, int length) throws IOException; + /** * Writes an array of bytes. * @@ -202,6 +229,8 @@ public void writeBytesRef(BytesRef bytes) throws IOException { write(bytes.bytes, bytes.offset, bytes.length); } + private static final ThreadLocal scratch = ThreadLocal.withInitial(() -> new byte[1024]); + public final void writeShort(short v) throws IOException { final byte[] buffer = scratch.get(); buffer[0] = (byte) (v >> 8); @@ -209,6 +238,49 @@ public final void writeShort(short v) throws IOException { writeBytes(buffer, 0, 2); } + /** + * Writes an int as four bytes. + */ + public void writeInt(int i) throws IOException { + final byte[] buffer = scratch.get(); + buffer[0] = (byte) (i >> 24); + buffer[1] = (byte) (i >> 16); + buffer[2] = (byte) (i >> 8); + buffer[3] = (byte) i; + writeBytes(buffer, 0, 4); + } + + /** + * Writes an int in a variable-length format. Writes between one and + * five bytes. Smaller values take fewer bytes. Negative numbers + * will always use all 5 bytes and are therefore better serialized + * using {@link #writeInt} + */ + public void writeVInt(int i) throws IOException { + /* + * Shortcut writing single byte because it is very, very common and + * can skip grabbing the scratch buffer. This is marginally slower + * than hand unrolling the entire encoding loop but hand unrolling + * the encoding loop blows out the method size so it can't be inlined. + * In that case benchmarks of the method itself are faster but + * benchmarks of methods that use this method are slower. + * This is philosophically in line with vint in general - it biases + * twoards being simple and fast for smaller numbers. + */ + if (Integer.numberOfLeadingZeros(i) >= 25) { + writeByte((byte) i); + return; + } + byte[] buffer = scratch.get(); + int index = 0; + do { + buffer[index++] = ((byte) ((i & 0x7f) | 0x80)); + i >>>= 7; + } while ((i & ~0x7F) != 0); + buffer[index++] = ((byte) i); + writeBytes(buffer, 0, index); + } + /** * Writes a long as eight bytes. */ @@ -250,7 +322,7 @@ public void writeOptionalVLong(@Nullable Long l) throws IOException { * Writes a long in a variable-length format without first checking if it is negative. Package private for testing. Use * {@link #writeVLong(long)} instead. */ - void writeVLongNoCheck(long i) throws IOException { + public void writeVLongNoCheck(long i) throws IOException { final byte[] buffer = scratch.get(); int index = 0; while ((i & ~0x7F) != 0) { @@ -312,6 +384,27 @@ public void writeOptionalSecureString(@Nullable SecureString secureStr) throws I } } + /** + * Writes an optional {@link Integer}. + */ + public void writeOptionalInt(@Nullable Integer integer) throws IOException { + if (integer == null) { + writeBoolean(false); + } else { + writeBoolean(true); + writeInt(integer); + } + } + + public void writeOptionalVInt(@Nullable Integer integer) throws IOException { + if (integer == null) { + writeBoolean(false); + } else { + writeBoolean(true); + writeVInt(integer); + } + } + public void writeOptionalFloat(@Nullable Float floatValue) throws IOException { if (floatValue == null) { writeBoolean(false); @@ -402,6 +495,39 @@ public final void writeBigInteger(BigInteger v) throws IOException { writeString(v.toString()); } + private static byte ZERO = 0; + private static byte ONE = 1; + private static byte TWO = 2; + + /** + * Writes a boolean. + */ + public void writeBoolean(boolean b) throws IOException { + writeByte(b ? ONE : ZERO); + } + + public void writeOptionalBoolean(@Nullable Boolean b) throws IOException { + if (b == null) { + writeByte(TWO); + } else { + writeBoolean(b); + } + } + + /** + * Forces any buffered output to be written. + */ + @Override + public abstract void flush() throws IOException; + + /** + * Closes this stream to further operations. + */ + @Override + public abstract void close() throws IOException; + + public abstract void reset() throws IOException; + @Override public void write(int b) throws IOException { writeByte((byte) b); @@ -532,10 +658,10 @@ public final void writeOptionalInstant(@Nullable Instant instant) throws IOExcep } } - private static final Map, BaseWriteable.Writer> WRITERS; + private static final Map, Writer> WRITERS; static { - Map, BaseWriteable.Writer> writers = new HashMap<>(); + Map, Writer> writers = new HashMap<>(); writers.put(String.class, (o, v) -> { o.writeByte((byte) 0); o.writeString((String) v); @@ -568,6 +694,7 @@ public final void writeOptionalInstant(@Nullable Instant instant) throws IOExcep }); writers.put(List.class, (o, v) -> { o.writeByte((byte) 7); + @SuppressWarnings("rawtypes") final List list = (List) v; o.writeVInt(list.size()); for (Object item : list) { @@ -659,7 +786,7 @@ public final void writeOptionalInstant(@Nullable Instant instant) throws IOExcep } private static Class getGenericType(Object value) { - Class registeredClass = Writeable.WriteableRegistry.getCustomClassFromInstance(value); + Class registeredClass = WriteableRegistry.getCustomClassFromInstance(value); if (registeredClass != null) { return registeredClass; } else if (value instanceof List) { @@ -689,7 +816,7 @@ public void writeGenericValue(@Nullable Object value) throws IOException { return; } final Class type = getGenericType(value); - BaseWriteable.Writer writer = BaseWriteable.WriteableRegistry.getWriter(type); + Writer writer = WriteableRegistry.getWriter(type); if (writer == null) { // fallback to this local hashmap // todo: move all writers to the registry @@ -938,14 +1065,14 @@ private void writeException(Throwable rootException, Throwable throwable, int ne writeBoolean(((OpenSearchRejectedExecutionException) throwable).isExecutorShutdown()); writeCause = false; } else { - final OpenSearchException ex; - if (throwable instanceof OpenSearchException && OpenSearchException.isRegistered(throwable.getClass(), version)) { - ex = (OpenSearchException) throwable; + final BaseOpenSearchException ex; + if (throwable instanceof BaseOpenSearchException && BaseOpenSearchException.isRegistered(throwable.getClass(), version)) { + ex = (BaseOpenSearchException) throwable; } else { ex = new NotSerializableExceptionWrapper(throwable); } writeVInt(0); - writeVInt(OpenSearchException.getId(ex.getClass())); + writeVInt(BaseOpenSearchException.getId(ex.getClass())); ex.writeTo(this); return; } @@ -955,7 +1082,7 @@ private void writeException(Throwable rootException, Throwable throwable, int ne if (writeCause) { writeException(rootException, throwable.getCause(), nestedLevel + 1); } - OpenSearchException.writeStackTraces(throwable, this, (o, t) -> o.writeException(rootException, t, nestedLevel + 1)); + BaseOpenSearchException.writeStackTraces(throwable, this, (o, t) -> o.writeException(rootException, t, nestedLevel + 1)); } } @@ -977,7 +1104,7 @@ public void writeBuild(final Build build) throws IOException { writeString(build.getQualifiedVersion()); } - boolean failOnTooManyNestedExceptions(Throwable throwable) { + protected boolean failOnTooManyNestedExceptions(Throwable throwable) { throw new AssertionError("too many nested exceptions", throwable); } @@ -1022,7 +1149,7 @@ public void writeOptionalZoneId(@Nullable ZoneId timeZone) throws IOException { /** * Writes a collection to this stream. The corresponding collection can be read from a stream input using - * {@link StreamInput#readList(BaseWriteable.Reader)}. + * {@link StreamInput#readList(Writeable.Reader)}. * * @param collection the collection to write to this stream * @throws IOException if an I/O exception occurs writing the collection @@ -1053,7 +1180,7 @@ public void writeCollection(final Collection collection, final Writer /** * Writes a collection of a strings. The corresponding collection can be read from a stream input using - * {@link StreamInput#readList(BaseWriteable.Reader)}. + * {@link StreamInput#readList(Writeable.Reader)}. * * @param collection the collection of strings * @throws IOException if an I/O exception occurs writing the collection @@ -1064,7 +1191,7 @@ public void writeStringCollection(final Collection collection) throws IO /** * Writes an optional collection of a strings. The corresponding collection can be read from a stream input using - * {@link StreamInput#readList(BaseWriteable.Reader)}. + * {@link StreamInput#readList(Writeable.Reader)}. * * @param collection the collection of strings * @throws IOException if an I/O exception occurs writing the collection diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java b/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java new file mode 100644 index 0000000000000..8ebf16b5ecdb9 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java @@ -0,0 +1,178 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +package org.opensearch.common.io.stream; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Implementers can be written to a {@linkplain StreamOutput} and read from a {@linkplain StreamInput}. This allows them to be "thrown + * across the wire" using OpenSearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by + * serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged. + * + * @opensearch.internal + */ +public interface Writeable { + /** + * A WriteableRegistry registers {@link Writer} methods for writing data types over a + * {@link StreamOutput} channel and {@link Reader} methods for reading data from a + * {@link StreamInput} channel. + * + * @opensearch.internal + */ + class WriteableRegistry { + private static final Map, Writer> WRITER_REGISTRY = new ConcurrentHashMap<>(); + private static final Map, Class> WRITER_CUSTOM_CLASS_MAP = new ConcurrentHashMap<>(); + private static final Map> READER_REGISTRY = new ConcurrentHashMap<>(); + + /** + * registers a streamable writer + * + * @opensearch.internal + */ + public static > void registerWriter(final Class clazz, final W writer) { + if (WRITER_REGISTRY.putIfAbsent(clazz, writer) != null) { + throw new IllegalArgumentException("Streamable writer already registered for type [" + clazz.getName() + "]"); + } + WRITER_REGISTRY.put(clazz, writer); + } + + /** + * registers a streamable reader + * + * @opensearch.internal + */ + public static > void registerReader(final byte ordinal, final R reader) { + if (READER_REGISTRY.putIfAbsent(ordinal, reader) != null) { + throw new IllegalArgumentException("Streamable reader already registered for ordinal [" + (int) ordinal + "]"); + } + READER_REGISTRY.put(ordinal, reader); + } + + public static void registerClassAlias(final Class classInstance, final Class classGeneric) { + if (WRITER_CUSTOM_CLASS_MAP.containsKey(classInstance)) { + throw new IllegalArgumentException("Streamable custom class already registered [" + classInstance.getClass() + "]"); + } + WRITER_CUSTOM_CLASS_MAP.put(classInstance, classGeneric); + } + + /** + * Returns the registered writer keyed by the class type + */ + @SuppressWarnings("unchecked") + public static > W getWriter(final Class clazz) { + return (W) WRITER_REGISTRY.get(clazz); + } + + /** + * Returns the ristered reader keyed by the unique ordinal + */ + @SuppressWarnings("unchecked") + public static > R getReader(final byte b) { + return (R) READER_REGISTRY.get(b); + } + + public static Class getCustomClassFromInstance(final Object value) { + if (value == null) { + throw new IllegalArgumentException("Attempting to retrieve a class type from a null value"); + } + // rip through registered classes; return the class iff 'value' is an instance + // we do it this way to cover inheritance and interfaces (e.g., joda DateTime is an instanceof + // a ReadableInstant interface) + for (final Class clazz : WRITER_CUSTOM_CLASS_MAP.values()) { + if (clazz.isInstance(value)) { + return clazz; + } + } + return null; + } + } + + /** + * Write this into the {@linkplain StreamOutput}. + */ + void writeTo(StreamOutput out) throws IOException; + + /** + * Reference to a method that can write some object to a {@link StreamOutput}. + *

+ * By convention this is a method from {@link StreamOutput} itself (e.g., {@code StreamOutput#writeString}). If the value can be + * {@code null}, then the "optional" variant of methods should be used! + *

+ * Most classes should implement {@code Writeable} and the {@code Writeable#writeTo(StreamOutput)} method should use + * {@link StreamOutput} methods directly or this indirectly: + *


+     * public void writeTo(StreamOutput out) throws IOException {
+     *     out.writeVInt(someValue);
+     *     out.writeMapOfLists(someMap, StreamOutput::writeString, StreamOutput::writeString);
+     * }
+     * 
+ */ + @FunctionalInterface + interface Writer { + + /** + * Write {@code V}-type {@code value} to the {@code out}put stream. + * + * @param out Output to write the {@code value} too + * @param value The value to add + */ + void write(final StreamOutput out, V value) throws IOException; + } + + /** + * Reference to a method that can read some object from a stream. By convention this is a constructor that takes + * {@linkplain StreamInput} as an argument for most classes and a static method for things like enums. Returning null from one of these + * is always wrong - for that we use methods like {@code StreamInput#readOptionalWriteable(Reader)}. + *

+ * As most classes will implement this via a constructor (or a static method in the case of enumerations), it's something that should + * look like: + *


+     * public MyClass(final StreamInput in) throws IOException {
+     *     this.someValue = in.readVInt();
+     *     this.someMap = in.readMapOfLists(StreamInput::readString, StreamInput::readString);
+     * }
+     * 
+ */ + @FunctionalInterface + interface Reader { + + /** + * Read {@code V}-type value from a stream. + * + * @param in Input to read the value from + */ + V read(final StreamInput in) throws IOException; + } +} diff --git a/server/src/main/java/org/opensearch/common/settings/SecureString.java b/libs/core/src/main/java/org/opensearch/common/settings/SecureString.java similarity index 100% rename from server/src/main/java/org/opensearch/common/settings/SecureString.java rename to libs/core/src/main/java/org/opensearch/common/settings/SecureString.java diff --git a/server/src/main/java/org/opensearch/common/text/Text.java b/libs/core/src/main/java/org/opensearch/common/text/Text.java similarity index 100% rename from server/src/main/java/org/opensearch/common/text/Text.java rename to libs/core/src/main/java/org/opensearch/common/text/Text.java diff --git a/server/src/main/java/org/opensearch/common/util/BigArray.java b/libs/core/src/main/java/org/opensearch/common/util/BigArray.java similarity index 100% rename from server/src/main/java/org/opensearch/common/util/BigArray.java rename to libs/core/src/main/java/org/opensearch/common/util/BigArray.java diff --git a/server/src/main/java/org/opensearch/common/util/ByteArray.java b/libs/core/src/main/java/org/opensearch/common/util/ByteArray.java similarity index 100% rename from server/src/main/java/org/opensearch/common/util/ByteArray.java rename to libs/core/src/main/java/org/opensearch/common/util/ByteArray.java diff --git a/server/src/main/java/org/opensearch/common/xcontent/XContentParserUtils.java b/libs/core/src/main/java/org/opensearch/common/xcontent/XContentParserUtils.java similarity index 100% rename from server/src/main/java/org/opensearch/common/xcontent/XContentParserUtils.java rename to libs/core/src/main/java/org/opensearch/common/xcontent/XContentParserUtils.java diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java b/libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java new file mode 100644 index 0000000000000..6ef33a190c352 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.core.common.io; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Util library for reading streams + * + * @opensearch.internal + */ +public final class StreamsUtil { + + private StreamsUtil() {} + + public static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException { + int read = 0; + while (read < len) { + final int r = reader.read(dest, offset + read, len - read); + if (r == -1) { + break; + } + read += r; + } + return read; + } +} diff --git a/server/src/main/java/org/opensearch/index/Index.java b/libs/core/src/main/java/org/opensearch/index/Index.java similarity index 100% rename from server/src/main/java/org/opensearch/index/Index.java rename to libs/core/src/main/java/org/opensearch/index/Index.java diff --git a/server/src/main/java/org/opensearch/index/shard/ShardId.java b/libs/core/src/main/java/org/opensearch/index/shard/ShardId.java similarity index 96% rename from server/src/main/java/org/opensearch/index/shard/ShardId.java rename to libs/core/src/main/java/org/opensearch/index/shard/ShardId.java index 9f226cd2df76a..ac24130ed90c9 100644 --- a/server/src/main/java/org/opensearch/index/shard/ShardId.java +++ b/libs/core/src/main/java/org/opensearch/index/shard/ShardId.java @@ -32,7 +32,7 @@ package org.opensearch.index.shard; -import org.opensearch.cluster.metadata.IndexMetadata; +import org.opensearch.core.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; @@ -109,7 +109,7 @@ public static ShardId fromString(String shardIdString) { } String indexName = shardIdString.substring(1, splitPosition); int shardId = Integer.parseInt(shardIdString.substring(splitPosition + 2, shardIdString.length() - 1)); - return new ShardId(new Index(indexName, IndexMetadata.INDEX_UUID_NA_VALUE), shardId); + return new ShardId(new Index(indexName, Strings.UNKNOWN_UUID_VALUE), shardId); } @Override diff --git a/server/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java b/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java similarity index 93% rename from server/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java rename to libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java index 0d8001ec3d730..82d57309fe922 100644 --- a/server/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java +++ b/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java @@ -32,7 +32,7 @@ package org.opensearch.index.snapshots; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.index.shard.ShardId; @@ -43,7 +43,7 @@ * * @opensearch.internal */ -public class IndexShardSnapshotException extends OpenSearchException { +public class IndexShardSnapshotException extends BaseOpenSearchException { public IndexShardSnapshotException(ShardId shardId, String msg) { this(shardId, msg, null); } diff --git a/server/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotFailedException.java b/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotFailedException.java similarity index 100% rename from server/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotFailedException.java rename to libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotFailedException.java diff --git a/server/src/main/java/org/opensearch/rest/RestStatus.java b/libs/core/src/main/java/org/opensearch/rest/RestStatus.java similarity index 100% rename from server/src/main/java/org/opensearch/rest/RestStatus.java rename to libs/core/src/main/java/org/opensearch/rest/RestStatus.java diff --git a/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java b/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java index f15823481180b..ecccfa936a6ac 100644 --- a/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java +++ b/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java @@ -33,7 +33,7 @@ package org.opensearch.common.xcontent; import org.opensearch.common.CheckedConsumer; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.MapXContentParser; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -98,11 +98,11 @@ public void compareTokens(CheckedConsumer consumer try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { consumer.accept(builder); final Map map; - try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { map = parser.mapOrdered(); } - try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { try ( XContentParser mapParser = new MapXContentParser( xContentRegistry(), diff --git a/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java b/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java index 2920a1ae6cf04..35186794f083d 100644 --- a/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java +++ b/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java @@ -38,7 +38,7 @@ import org.opensearch.common.CheckedSupplier; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.cbor.CborXContent; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.common.xcontent.smile.SmileXContent; @@ -110,7 +110,7 @@ public void testStringOffLimit() throws IOException { } builder.endObject(); - try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(field, parser.currentName()); @@ -140,7 +140,7 @@ public void testString() throws IOException { builder.endObject(); final String text; - try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(field, parser.currentName()); @@ -172,7 +172,7 @@ public void testFloat() throws IOException { builder.endObject(); final Number number; - try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(field, parser.currentName()); diff --git a/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java index a7825edcf6b3a..bd0f923e37484 100644 --- a/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java @@ -33,7 +33,7 @@ package org.opensearch.ingest.common; import org.opensearch.common.Nullable; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -136,7 +136,7 @@ public ScriptProcessor create( ) throws Exception { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - InputStream stream = BytesReference.bytes(builder).streamInput(); + InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java index db8c04cca7c80..1ef3a38d519a9 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java @@ -34,9 +34,9 @@ import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -123,7 +123,8 @@ public void testResponseToXContent() throws Exception { GrokProcessorGetAction.Response response = new GrokProcessorGetAction.Response(TEST_PATTERNS); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - Map converted = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map converted = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()) + .v2(); Map patterns = (Map) converted.get("patterns"); assertThat(patterns.size(), equalTo(2)); assertThat(patterns.get("PATTERN1"), equalTo("foo1")); diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java index f2cc33e10abfe..6c9796b981e9b 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java @@ -32,7 +32,7 @@ package org.opensearch.ingest.common; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -61,7 +61,7 @@ public void testExecute() throws Exception { Map randomJsonMap = RandomDocumentPicks.randomSource(random()); XContentBuilder builder = JsonXContent.contentBuilder().map(randomJsonMap); - String randomJson = XContentHelper.convertToJson(BytesReference.bytes(builder), false, XContentType.JSON); + String randomJson = XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder), false, XContentType.JSON); document.put(randomField, randomJson); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); diff --git a/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java b/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java index 6ec147c7390a9..47b02223fd911 100644 --- a/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java +++ b/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java @@ -39,6 +39,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -156,7 +157,7 @@ public void testLazyLoading() throws IOException { builder.endArray(); } builder.endObject(); - bytes = BytesReference.bytes(builder); + bytes = BytesReferenceUtil.bytes(builder); } assertAcked(client().admin().cluster().putPipeline(new PutPipelineRequest("geoip", bytes, XContentType.JSON)).actionGet()); // the geo-IP databases should not be loaded on any nodes as they are all non-ingest nodes diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java index 35363275da304..34ac30bb439d3 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java @@ -38,9 +38,9 @@ import org.opensearch.action.search.MultiSearchRequest; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.support.IndicesOptions; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -164,12 +164,12 @@ public static byte[] writeMultiLineFormat(MultiSearchTemplateRequest multiSearch final SearchRequest searchRequest = templateRequest.getRequest(); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { MultiSearchRequest.writeSearchRequestParams(searchRequest, xContentBuilder); - BytesReference.bytes(xContentBuilder).writeTo(output); + BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { templateRequest.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); - BytesReference.bytes(xContentBuilder).writeTo(output); + BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); } diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java index 87f3b9f902b8f..88ba637c43ebf 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java @@ -34,6 +34,7 @@ import org.opensearch.action.ActionResponse; import org.opensearch.action.search.SearchResponse; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -105,12 +106,16 @@ public static SearchTemplateResponse fromXContent(XContentParser parser) throws if (contentAsMap.containsKey(TEMPLATE_OUTPUT_FIELD.getPreferredName())) { Object source = contentAsMap.get(TEMPLATE_OUTPUT_FIELD.getPreferredName()); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).value(source); - searchTemplateResponse.setSource(BytesReference.bytes(builder)); + searchTemplateResponse.setSource(BytesReferenceUtil.bytes(builder)); } else { MediaType contentType = parser.contentType(); XContentBuilder builder = XContentFactory.contentBuilder(contentType).map(contentAsMap); XContentParser searchResponseParser = contentType.xContent() - .createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), BytesReference.bytes(builder).streamInput()); + .createParser( + parser.getXContentRegistry(), + parser.getDeprecationHandler(), + BytesReferenceUtil.bytes(builder).streamInput() + ); SearchResponse searchResponse = SearchResponse.fromXContent(searchResponseParser); searchTemplateResponse.setResponse(searchResponse); diff --git a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java index bc44821416fbe..30168b42b82df 100644 --- a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java +++ b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java @@ -31,7 +31,7 @@ package org.opensearch.script.mustache; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.script.ScriptEngine; @@ -276,7 +276,7 @@ public void testEmbeddedToJSON() throws Exception { Map ctx = singletonMap( "ctx", - XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2() + XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2() ); assertScript( @@ -322,7 +322,7 @@ public void testEmbeddedArrayJoin() throws Exception { Map ctx = singletonMap( "ctx", - XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2() + XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2() ); assertScript("{{#join}}ctx.people.0.emails{{/join}}", ctx, equalTo("john@smith.com,john.smith@email.com,jsmith@email.com")); diff --git a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java index 1e997eee9ff22..c2ee89ad0e5bd 100644 --- a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java +++ b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java @@ -32,7 +32,7 @@ package org.opensearch.script.mustache; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -115,7 +115,7 @@ public void testToXContentWithInlineTemplate() throws IOException { XContentBuilder actualRequest = XContentFactory.contentBuilder(contentType); request.toXContent(actualRequest, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReference.bytes(expectedRequest), BytesReference.bytes(actualRequest), contentType); + assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedRequest), BytesReferenceUtil.bytes(actualRequest), contentType); } public void testToXContentWithStoredTemplate() throws IOException { @@ -145,7 +145,7 @@ public void testToXContentWithStoredTemplate() throws IOException { XContentBuilder actualRequest = XContentFactory.contentBuilder(contentType); request.toXContent(actualRequest, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReference.bytes(expectedRequest), BytesReference.bytes(actualRequest), contentType); + assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedRequest), BytesReferenceUtil.bytes(actualRequest), contentType); } public void testFromXContentWithEmbeddedTemplate() throws Exception { diff --git a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java index 642625f932155..48735b176e321 100644 --- a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java +++ b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java @@ -36,6 +36,7 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.action.search.ShardSearchFailure; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -103,7 +104,7 @@ private static BytesReference createSource() { .endObject() .endObject() .endObject(); - return BytesReference.bytes(source); + return BytesReferenceUtil.bytes(source); } catch (IOException e) { throw new RuntimeException(e); } @@ -161,7 +162,7 @@ public void testSourceToXContent() throws IOException { .endObject() .endObject() .endObject(); - response.setSource(BytesReference.bytes(source)); + response.setSource(BytesReferenceUtil.bytes(source)); XContentType contentType = randomFrom(XContentType.values()); XContentBuilder expectedResponse = XContentFactory.contentBuilder(contentType) @@ -178,7 +179,7 @@ public void testSourceToXContent() throws IOException { XContentBuilder actualResponse = XContentFactory.contentBuilder(contentType); response.toXContent(actualResponse, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReference.bytes(expectedResponse), BytesReference.bytes(actualResponse), contentType); + assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedResponse), BytesReferenceUtil.bytes(actualResponse), contentType); } public void testSearchResponseToXContent() throws IOException { @@ -238,6 +239,6 @@ public void testSearchResponseToXContent() throws IOException { XContentBuilder actualResponse = XContentFactory.contentBuilder(contentType); response.toXContent(actualResponse, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReference.bytes(expectedResponse), BytesReference.bytes(actualResponse), contentType); + assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedResponse), BytesReferenceUtil.bytes(actualResponse), contentType); } } diff --git a/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java index 18f854b3d1ea2..5e4f045b8f047 100644 --- a/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java @@ -63,6 +63,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -164,7 +165,7 @@ static class ContextSetup implements Writeable, ToXContentObject { PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> { try (XContentBuilder b = XContentBuilder.builder(p.contentType().xContent())) { b.copyCurrentStructure(p); - return BytesReference.bytes(b); + return BytesReferenceUtil.bytes(b); } }, DOCUMENT_FIELD); PARSER.declareObject( diff --git a/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java b/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java index baa43625054aa..4335cadc48d52 100644 --- a/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java +++ b/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java @@ -36,6 +36,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContent; @@ -75,7 +76,7 @@ public final void testFromXContent() throws Exception { try (XContentBuilder builder = XContentBuilder.builder(xContent)) { builder.value(testInstance); - StreamInput instanceInput = BytesReference.bytes(builder).streamInput(); + StreamInput instanceInput = BytesReferenceUtil.bytes(builder).streamInput(); try (XContentParser parser = xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, instanceInput)) { PainlessExecuteAction.Request result = PainlessExecuteAction.Request.parse(parser); assertThat(result, equalTo(testInstance)); @@ -125,7 +126,7 @@ private static ContextSetup randomContextSetup() { XContentBuilder xContentBuilder = XContentBuilder.builder(xContentType.xContent()); xContentBuilder.startObject(); xContentBuilder.endObject(); - doc = BytesReference.bytes(xContentBuilder); + doc = BytesReferenceUtil.bytes(xContentBuilder); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java index 63487fd7baa89..dde0a75e5d8ea 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -88,7 +89,7 @@ public void testDocumentParsingFailsOnMetaField() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject()); DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); String rfMetaField = RankFeatureMetaFieldMapper.CONTENT_TYPE; - BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(rfMetaField, 0).endObject()); + BytesReference bytes = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(rfMetaField, 0).endObject()); MapperParsingException e = expectThrows( MapperParsingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON)) diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java index 2662605cbfe5b..5360c90b1766d 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -35,7 +35,7 @@ import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -135,7 +135,7 @@ public void testNotIndexed() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), XContentType.JSON ) ); @@ -156,7 +156,7 @@ public void testNoDocValues() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), XContentType.JSON ) ); @@ -177,7 +177,7 @@ public void testStore() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), XContentType.JSON ) ); @@ -200,7 +200,7 @@ public void testCoerce() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), XContentType.JSON ) ); @@ -219,7 +219,7 @@ public void testCoerce() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), XContentType.JSON ) ); @@ -243,7 +243,7 @@ private void doTestIgnoreMalformed(Object value, String exceptionMessageContains new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), XContentType.JSON ) ); @@ -257,7 +257,7 @@ private void doTestIgnoreMalformed(Object value, String exceptionMessageContains new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), XContentType.JSON ) ); @@ -272,7 +272,7 @@ public void testNullValue() throws IOException { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), XContentType.JSON ) ); @@ -285,7 +285,7 @@ public void testNullValue() throws IOException { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), XContentType.JSON ) ); diff --git a/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java b/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java index 53e9495b707fe..4206e19a91acf 100644 --- a/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java +++ b/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java @@ -33,8 +33,8 @@ package org.opensearch.join.mapper; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -80,7 +80,12 @@ public void testSingleLevel() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse( - new SourceToParse("test", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON) + new SourceToParse( + "test", + "0", + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().endObject()), + XContentType.JSON + ) ); assertNull(doc.rootDoc().getBinaryValue("join_field")); @@ -89,7 +94,7 @@ public void testSingleLevel() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), XContentType.JSON ) ); @@ -101,7 +106,7 @@ public void testSingleLevel() throws Exception { new SourceToParse( "test", "2", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -124,7 +129,7 @@ public void testSingleLevel() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), XContentType.JSON ) ) @@ -153,7 +158,7 @@ public void testParentIdSpecifiedAsNumber() throws Exception { new SourceToParse( "test", "2", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -172,7 +177,7 @@ public void testParentIdSpecifiedAsNumber() throws Exception { new SourceToParse( "test", "2", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -211,7 +216,12 @@ public void testMultipleLevels() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse( - new SourceToParse("test", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON) + new SourceToParse( + "test", + "0", + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().endObject()), + XContentType.JSON + ) ); assertNull(doc.rootDoc().getBinaryValue("join_field")); @@ -220,7 +230,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), XContentType.JSON ) ); @@ -232,7 +242,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "2", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -256,7 +266,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "2", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "child").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "child").endObject()), XContentType.JSON, "1" ) @@ -271,7 +281,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "2", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -291,7 +301,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "3", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -314,7 +324,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), XContentType.JSON ) ) diff --git a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java index a0b04f62a84b6..16fe05ca562b9 100644 --- a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java @@ -41,6 +41,7 @@ import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.DistanceUnit; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -123,13 +124,13 @@ public void testPercolatorQuery() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - BytesReference source = BytesReference.bytes(jsonBuilder().startObject().endObject()); + BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().endObject()); logger.info("percolating empty doc"); SearchResponse response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); - source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); logger.info("percolating doc with 1 field"); response = client().prepareSearch() .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) @@ -141,7 +142,7 @@ public void testPercolatorQuery() throws Exception { assertThat(response.getHits().getAt(1).getId(), equalTo("2")); assertThat(response.getHits().getAt(1).getFields().get("_percolator_document_slot").getValue(), equalTo(0)); - source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()); logger.info("percolating doc with 2 fields"); response = client().prepareSearch() .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) @@ -161,8 +162,8 @@ public void testPercolatorQuery() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), - BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()) + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()) ), XContentType.JSON ) @@ -266,44 +267,44 @@ public void testPercolatorRangeQueries() throws Exception { client().admin().indices().prepareRefresh().get(); // Test long range: - BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("field1", 12).endObject()); + BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", 12).endObject()); SearchResponse response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); logger.info("response={}", response); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("3")); assertThat(response.getHits().getAt(1).getId(), equalTo("1")); - source = BytesReference.bytes(jsonBuilder().startObject().field("field1", 11).endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", 11).endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); // Test double range: - source = BytesReference.bytes(jsonBuilder().startObject().field("field2", 12).endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field2", 12).endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("6")); assertThat(response.getHits().getAt(1).getId(), equalTo("4")); - source = BytesReference.bytes(jsonBuilder().startObject().field("field2", 11).endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field2", 11).endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("4")); // Test IP range: - source = BytesReference.bytes(jsonBuilder().startObject().field("field3", "192.168.1.5").endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field3", "192.168.1.5").endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("9")); assertThat(response.getHits().getAt(1).getId(), equalTo("7")); - source = BytesReference.bytes(jsonBuilder().startObject().field("field3", "192.168.1.4").endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field3", "192.168.1.4").endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("7")); // Test date range: - source = BytesReference.bytes(jsonBuilder().startObject().field("field4", "2016-05-15").endObject()); + source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field4", "2016-05-15").endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("10")); @@ -351,7 +352,7 @@ public void testPercolatorGeoQueries() throws Exception { .get(); refresh(); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject().startObject("field1").field("lat", 52.20).field("lon", 4.51).endObject().endObject() ); SearchResponse response = client().prepareSearch() @@ -521,7 +522,7 @@ public void testPercolatorSpecificQueries() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("field1", "the quick brown fox jumps over the lazy dog") .field("field2", "the quick brown fox falls down into the well") @@ -582,7 +583,7 @@ public void testPercolatorQueryWithHighlighting() throws Exception { .actionGet(); client().admin().indices().prepareRefresh().get(); - BytesReference document = BytesReference.bytes( + BytesReference document = BytesReferenceUtil.bytes( jsonBuilder().startObject().field("field1", "The quick brown fox jumps over the lazy dog").endObject() ); SearchResponse searchResponse = client().prepareSearch() @@ -613,10 +614,10 @@ public void testPercolatorQueryWithHighlighting() throws Exception { equalTo("The quick brown fox jumps over the lazy dog") ); - BytesReference document1 = BytesReference.bytes( + BytesReference document1 = BytesReferenceUtil.bytes( jsonBuilder().startObject().field("field1", "The quick brown fox jumps").endObject() ); - BytesReference document2 = BytesReference.bytes(jsonBuilder().startObject().field("field1", "over the lazy dog").endObject()); + BytesReference document2 = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "over the lazy dog").endObject()); searchResponse = client().prepareSearch() .setQuery( boolQuery().should(new PercolateQueryBuilder("query", document1, XContentType.JSON).setName("query1")) @@ -654,10 +655,10 @@ public void testPercolatorQueryWithHighlighting() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReference.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), - BytesReference.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()), - BytesReference.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), - BytesReference.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) ), XContentType.JSON ) @@ -709,8 +710,8 @@ public void testPercolatorQueryWithHighlighting() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReference.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), - BytesReference.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()) + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()) ), XContentType.JSON ).setName("query1") @@ -719,8 +720,8 @@ public void testPercolatorQueryWithHighlighting() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReference.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), - BytesReference.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) ), XContentType.JSON ).setName("query2") @@ -897,7 +898,7 @@ public void testWithMultiplePercolatorFields() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field", "value").endObject()); SearchResponse response = client().prepareSearch() .setQuery(new PercolateQueryBuilder(queryFieldName, source, XContentType.JSON)) .setIndices("test1") @@ -998,7 +999,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1025,7 +1026,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "notstark") @@ -1051,7 +1052,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("companyname", "notstark").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("companyname", "notstark").endObject()), XContentType.JSON ) ) @@ -1065,7 +1066,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1079,7 +1080,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .endArray() .endObject() ), - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1093,7 +1094,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .endArray() .endObject() ), - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1157,7 +1158,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), XContentType.JSON ) ) @@ -1167,7 +1168,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(yamlBuilder().startObject().field("field1", "c").endObject()), + BytesReferenceUtil.bytes(yamlBuilder().startObject().field("field1", "c").endObject()), XContentType.YAML ) ) @@ -1177,7 +1178,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(jsonBuilder().startObject().field("field1", "b c").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "b c").endObject()), XContentType.JSON ) ) @@ -1187,7 +1188,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(jsonBuilder().startObject().field("field1", "d").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "d").endObject()), XContentType.JSON ) ) @@ -1246,7 +1247,7 @@ public void testDisallowExpensiveQueries() throws IOException { refresh(); // Execute with search.allow_expensive_queries = null => default value = false => success - BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); + BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); SearchResponse response = client().prepareSearch() .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) .get(); @@ -1306,7 +1307,7 @@ public void testWrappedWithConstantScore() throws Exception { .setQuery( new PercolateQueryBuilder( "q", - BytesReference.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), XContentType.JSON ) ) @@ -1317,7 +1318,7 @@ public void testWrappedWithConstantScore() throws Exception { .setQuery( new PercolateQueryBuilder( "q", - BytesReference.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), XContentType.JSON ) ) @@ -1330,7 +1331,7 @@ public void testWrappedWithConstantScore() throws Exception { constantScoreQuery( new PercolateQueryBuilder( "q", - BytesReference.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), XContentType.JSON ) ) diff --git a/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java index 498b58c8b6bba..0f034c510b44b 100644 --- a/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java @@ -66,6 +66,7 @@ import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -392,7 +393,7 @@ private static BytesReference parseDocument(XContentParser parser) throws IOExce try (XContentBuilder builder = XContentFactory.jsonBuilder()) { builder.copyCurrentStructure(parser); builder.flush(); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java index 5014b838d94e3..015e6e5b52df2 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java @@ -44,6 +44,7 @@ import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.lucene.uid.Versions; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -319,7 +320,7 @@ private static BytesReference randomSource(Set usedFields) { XContentBuilder xContent = XContentFactory.jsonBuilder(); xContent.map(source); - return BytesReference.bytes(xContent); + return BytesReferenceUtil.bytes(xContent); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java index eb76229801479..d8004d3364a1e 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java @@ -58,7 +58,6 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.hash.MurmurHash3; @@ -68,6 +67,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.network.InetAddresses; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -559,7 +559,7 @@ public void testPercolatorFieldMapper() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -579,7 +579,7 @@ public void testPercolatorFieldMapper() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -596,7 +596,7 @@ public void testPercolatorFieldMapper() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -624,7 +624,7 @@ public void testStoringQueries() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, query).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, query).endObject()), XContentType.JSON ) ); @@ -642,7 +642,7 @@ public void testQueryWithRewrite() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -666,7 +666,7 @@ public void testPercolatorFieldMapperUnMappedField() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder().startObject().field(fieldName, termQuery("unmapped_field", "value")).endObject() ), XContentType.JSON @@ -684,7 +684,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON ) ); @@ -696,7 +696,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject()), XContentType.JSON ) ); @@ -758,7 +758,7 @@ public void testMultiplePercolatorFields() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject().field("query_field1", queryBuilder).field("query_field2", queryBuilder).endObject() ), XContentType.JSON @@ -800,7 +800,7 @@ public void testNestedPercolatorField() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject().startObject("object_field").field("query_field", queryBuilder).endObject().endObject() ), XContentType.JSON @@ -819,7 +819,7 @@ public void testNestedPercolatorField() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("object_field") .startObject() @@ -841,7 +841,7 @@ public void testNestedPercolatorField() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("object_field") .startObject() @@ -948,7 +948,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) @@ -995,7 +995,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) @@ -1089,7 +1089,7 @@ public void testDuplicatedClauses() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), XContentType.JSON ) ); @@ -1114,7 +1114,7 @@ public void testDuplicatedClauses() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), XContentType.JSON ) ); @@ -1142,7 +1142,7 @@ public void testDuplicatedClauses() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), XContentType.JSON ) ); diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java index 1e85e1ad18314..c8bd50ef55dab 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java @@ -37,6 +37,7 @@ import org.opensearch.action.support.WriteRequest; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -114,7 +115,7 @@ public void testPercolateScriptQuery() throws IOException { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), XContentType.JSON ) ) @@ -174,7 +175,7 @@ public void testPercolateQueryWithNestedDocuments_doNotLeakBitsetCacheEntries() .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -269,7 +270,7 @@ public void testPercolateQueryWithNestedDocuments_doLeakFieldDataCacheEntries() doc.endObject(); for (int i = 0; i < 32; i++) { SearchResponse response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", BytesReference.bytes(doc), XContentType.JSON)) + .setQuery(new PercolateQueryBuilder("query", BytesReferenceUtil.bytes(doc), XContentType.JSON)) .addSort("_doc", SortOrder.ASC) .get(); assertHitCount(response, 1); @@ -292,7 +293,7 @@ public void testMapUnmappedFieldAsText() throws IOException { .setQuery( new PercolateQueryBuilder( "query", - BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), + BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), XContentType.JSON ) ) @@ -345,7 +346,7 @@ public void testRangeQueriesWithNow() throws Exception { long[] currentTime = new long[] { System.currentTimeMillis() }; QueryShardContext queryShardContext = indexService.newQueryShardContext(0, searcher, () -> currentTime[0], null); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject().field("field1", "value").field("field2", currentTime[0]).endObject() ); QueryBuilder queryBuilder = new PercolateQueryBuilder("query", source, XContentType.JSON); @@ -353,7 +354,9 @@ public void testRangeQueriesWithNow() throws Exception { assertThat(searcher.count(query), equalTo(3)); currentTime[0] = currentTime[0] + 10800000; // + 3 hours - source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", currentTime[0]).endObject()); + source = BytesReferenceUtil.bytes( + jsonBuilder().startObject().field("field1", "value").field("field2", currentTime[0]).endObject() + ); queryBuilder = new PercolateQueryBuilder("query", source, XContentType.JSON); query = queryBuilder.toQuery(queryShardContext); assertThat(searcher.count(query), equalTo(3)); diff --git a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java index 58a940e1618da..c3f9fa01a047b 100644 --- a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java +++ b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java @@ -33,7 +33,6 @@ package org.opensearch.index.rankeval; import org.opensearch.BaseOpenSearchException; -import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; @@ -167,7 +166,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws PARSER.declareNamedObjects(ConstructingObjectParser.optionalConstructorArg(), (p, c, n) -> { XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, p.nextToken(), p); XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p); - Tuple tuple = new Tuple<>(n, OpenSearchException.failureFromXContent(p)); + Tuple tuple = new Tuple<>(n, BaseOpenSearchException.failureFromXContent(p)); XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, p.nextToken(), p); return tuple; }, FAILURES_FIELD); diff --git a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java index b52c1c1897086..5183d1df8f82e 100644 --- a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java +++ b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java @@ -32,6 +32,7 @@ package org.opensearch.index.rankeval; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.search.SearchPhaseExecutionException; @@ -44,6 +45,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -165,7 +167,7 @@ public void testXContentParsing() throws IOException { assertEquals(testItem.getFailures().keySet(), parsedItem.getFailures().keySet()); for (String queryId : testItem.getFailures().keySet()) { Exception ex = parsedItem.getFailures().get(queryId); - assertThat(ex, instanceOf(OpenSearchException.class)); + assertThat(ex, instanceOf(BaseOpenSearchException.class)); } } @@ -178,7 +180,7 @@ public void testToXContent() throws IOException { Collections.singletonMap("beer_query", new ParsingException(new XContentLocation(0, 0), "someMsg")) ); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); - String xContent = BytesReference.bytes(response.toXContent(builder, ToXContent.EMPTY_PARAMS)).utf8ToString(); + String xContent = BytesReferenceUtil.bytes(response.toXContent(builder, ToXContent.EMPTY_PARAMS)).utf8ToString(); assertEquals( ("{" + " \"metric_score\": 0.123," diff --git a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java index e4a21b61052cd..87e0cf8765f76 100644 --- a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java +++ b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -142,7 +143,7 @@ static RankEvalSpec createTestItem() { public void testXContentRoundtrip() throws IOException { RankEvalSpec testItem = createTestItem(); XContentBuilder shuffled = shuffleXContent(testItem.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(shuffled))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(shuffled))) { RankEvalSpec parsedItem = RankEvalSpec.parse(parser); assertNotSame(testItem, parsedItem); assertEquals(testItem, parsedItem); diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java index 7367182150aea..836fa5249f4c1 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java @@ -34,8 +34,8 @@ import org.opensearch.action.ActionType; import org.opensearch.action.search.SearchRequest; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -121,7 +121,7 @@ private XContentParser extractRequestSpecificFields(RestRequest restRequest, Map .createParser( parser.getXContentRegistry(), parser.getDeprecationHandler(), - BytesReference.bytes(builder.map(body)).streamInput() + BytesReferenceUtil.bytes(builder.map(body)).streamInput() ); } } diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java index a5107597e4113..c82496ee44a4a 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java @@ -57,8 +57,8 @@ import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.lucene.uid.Versions; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -390,7 +390,7 @@ protected RequestWrapper buildRequest(ScrollableHitSource.Hit doc) ) { parser.nextToken(); builder.copyCurrentStructure(parser); - index.source(BytesReference.bytes(builder), builder.contentType()); + index.source(BytesReferenceUtil.bytes(builder), builder.contentType()); } catch (IOException e) { throw new UncheckedIOException( "failed to convert hit from " + sourceXContentType + " to " + mainRequestXContentType, diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java index b1e4d53c90d92..9f982cf10e69a 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java @@ -35,9 +35,9 @@ import org.apache.lucene.search.TotalHits; import org.opensearch.LegacyESVersion; import org.opensearch.Version; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import org.opensearch.core.xcontent.ConstructingObjectParser; @@ -92,7 +92,7 @@ private RemoteResponseParsers() {} try (XContentBuilder b = XContentBuilder.builder(s.xContent())) { b.copyCurrentStructure(p); // a hack but this lets us get the right xcontent type to go with the source - return new Tuple<>(BytesReference.bytes(b), s); + return new Tuple<>(BytesReferenceUtil.bytes(b), s); } } catch (IOException e) { throw new ParsingException(p.getTokenLocation(), "[hit] failed to parse [_source]", e); diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java index 4b9aa0ac2ce62..a72f61aaeba43 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.reindex; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -74,7 +74,7 @@ public void testPipelineQueryParameterIsError() throws IOException { body.endObject(); } body.endObject(); - request.withContent(BytesReference.bytes(body), XContentType.fromMediaType(body.contentType())); + request.withContent(BytesReferenceUtil.bytes(body), XContentType.fromMediaType(body.contentType())); } request.withParams(singletonMap("pipeline", "doesn't matter")); Exception e = expectThrows( diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java index 7deb8faa03af6..1e59c34764734 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java @@ -9,7 +9,7 @@ package org.opensearch.search.pipeline.common; import org.opensearch.action.search.SearchRequest; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -105,7 +105,7 @@ public FilterQueryRequestProcessor create( ) throws Exception { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - InputStream stream = BytesReference.bytes(builder).streamInput(); + InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java index 4c40dda5928f0..22fdebc3b9573 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java @@ -13,6 +13,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.common.document.DocumentField; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.XContentBuilder; @@ -113,7 +114,7 @@ public SearchResponse processResponse(SearchRequest request, SearchResponse resp XContentBuilder builder = XContentBuilder.builder(typeAndSourceMap.v1().xContent()); builder.map(sourceAsMap); - hit.sourceRef(BytesReference.bytes(builder)); + hit.sourceRef(BytesReferenceUtil.bytes(builder)); } } diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java index 015411e0701a4..db99bd2baf4d5 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java @@ -11,7 +11,7 @@ import org.opensearch.action.search.SearchRequest; import org.opensearch.common.Nullable; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -157,7 +157,7 @@ public ScriptRequestProcessor create( ) throws Exception { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - InputStream stream = BytesReference.bytes(builder).streamInput(); + InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java index 4e4648a87fbfc..dc71d64eb7233 100644 --- a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java @@ -38,6 +38,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -65,7 +66,7 @@ public void testSizeEnabled() throws Exception { IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true"); DocumentMapper docMapper = service.mapperService().documentMapper(); - BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); ParsedDocument doc = docMapper.parse(new SourceToParse("test", "1", source, XContentType.JSON)); boolean stored = false; @@ -82,7 +83,7 @@ public void testSizeDisabled() throws Exception { IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=false"); DocumentMapper docMapper = service.mapperService().documentMapper(); - BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); ParsedDocument doc = docMapper.parse(new SourceToParse("test", "1", source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); @@ -92,7 +93,7 @@ public void testSizeNotSet() throws Exception { IndexService service = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME); DocumentMapper docMapper = service.mapperService().documentMapper(); - BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); ParsedDocument doc = docMapper.parse(new SourceToParse("test", "1", source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); diff --git a/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java b/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java index 1c89c0df962ee..b9bf44eca4681 100644 --- a/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java +++ b/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java @@ -41,6 +41,7 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.test.OpenSearchTestCase; @@ -185,7 +186,7 @@ private byte[] serviceAccountFileContent(String projectId) throws Exception { .field("client_email", "integration_test@appspot.gserviceaccount.com") .field("client_id", "client_id") .endObject(); - return BytesReference.toBytes(BytesReference.bytes(serviceAccountBuilder)); + return BytesReference.toBytes(BytesReferenceUtil.bytes(serviceAccountBuilder)); } public void testToTimeout() { diff --git a/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java b/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java index 07cd901449a18..00228e39d2184 100644 --- a/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java +++ b/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java @@ -36,6 +36,7 @@ import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.io.entity.StringEntity; import org.apache.lucene.search.TotalHits; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsAction; @@ -295,21 +296,21 @@ public void testSkipUnavailableDependsOnSeeds() throws IOException { private static void assertSearchConnectFailure() { { - OpenSearchException exception = expectThrows(OpenSearchException.class, + BaseOpenSearchException exception = expectThrows(BaseOpenSearchException.class, () -> restHighLevelClient.search(new SearchRequest("index", "remote1:index"), RequestOptions.DEFAULT)); - OpenSearchException rootCause = (OpenSearchException)exception.getRootCause(); + BaseOpenSearchException rootCause = (BaseOpenSearchException)exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("connect_exception")); } { - OpenSearchException exception = expectThrows(OpenSearchException.class, + BaseOpenSearchException exception = expectThrows(BaseOpenSearchException.class, () -> restHighLevelClient.search(new SearchRequest("remote1:index"), RequestOptions.DEFAULT)); - OpenSearchException rootCause = (OpenSearchException)exception.getRootCause(); + BaseOpenSearchException rootCause = (BaseOpenSearchException)exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("connect_exception")); } { - OpenSearchException exception = expectThrows(OpenSearchException.class, + BaseOpenSearchException exception = expectThrows(BaseOpenSearchException.class, () -> restHighLevelClient.search(new SearchRequest("remote1:index").scroll("1m"), RequestOptions.DEFAULT)); - OpenSearchException rootCause = (OpenSearchException)exception.getRootCause(); + BaseOpenSearchException rootCause = (BaseOpenSearchException)exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("connect_exception")); } } diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/DetailedErrorsEnabledIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/DetailedErrorsEnabledIT.java index e2ccf86d31dbf..76f801c75d866 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/DetailedErrorsEnabledIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/DetailedErrorsEnabledIT.java @@ -58,7 +58,7 @@ public void testThatErrorTraceWorksByDefault() throws IOException, ParseExceptio Response response = e.getResponse(); assertThat(response.getHeader("Content-Type"), containsString("application/json")); assertThat(EntityUtils.toString(response.getEntity()), - containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; " + + containsString("\"stack_trace\":\"OpenSearchException[Validation Failed: 1: index / indices is missing;]; " + "nested: ActionRequestValidationException[Validation Failed: 1:")); } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java index 67e52529ae86b..33229ebad464e 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java @@ -32,8 +32,8 @@ package org.opensearch.action.admin.cluster.node.tasks; +import org.opensearch.BaseOpenSearchException; import org.opensearch.ExceptionsHelper; -import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.action.ActionFuture; import org.opensearch.action.ActionListener; @@ -769,7 +769,7 @@ public void testTasksWaitForAllTask() throws Exception { .get(); // It should finish quickly and without complaint and list the list tasks themselves - assertThat(response.getNodeFailures(), emptyCollectionOf(OpenSearchException.class)); + assertThat(response.getNodeFailures(), emptyCollectionOf(BaseOpenSearchException.class)); assertThat(response.getTaskFailures(), emptyCollectionOf(TaskOperationFailure.class)); assertThat(response.getTasks().size(), greaterThanOrEqualTo(1)); } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java index ec8d02a8c57b7..9fbd9fa374a47 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java @@ -45,7 +45,7 @@ import org.opensearch.action.support.replication.ReplicationRequest; import org.opensearch.action.update.UpdateRequest; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.IngestTestPlugin; @@ -183,7 +183,7 @@ private void createSamplePipeline(String pipelineId) throws IOException, Executi AcknowledgedResponse acknowledgedResponse = client().admin() .cluster() - .putPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(pipeline), XContentType.JSON)) + .putPipeline(new PutPipelineRequest(pipelineId, BytesReferenceUtil.bytes(pipeline), XContentType.JSON)) .get(); assertTrue(acknowledgedResponse.isAcknowledged()); diff --git a/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java b/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java index 2f811d4a901bf..c05e1cbea7b79 100644 --- a/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java @@ -49,6 +49,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.engine.VersionConflictEngineException; @@ -606,7 +607,7 @@ public void testGetFieldsComplexField() throws Exception { ) ); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("field1") .startObject() diff --git a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java index 522938003838b..b02db70b70f0e 100644 --- a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java @@ -53,6 +53,7 @@ import org.opensearch.client.Requests; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; @@ -89,7 +90,7 @@ protected Collection> nodePlugins() { } public void testSimulate() throws Exception { - BytesReference pipelineSource = BytesReference.bytes( + BytesReference pipelineSource = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -106,7 +107,7 @@ public void testSimulate() throws Exception { assertThat(getResponse.pipelines().size(), equalTo(1)); assertThat(getResponse.pipelines().get(0).getId(), equalTo("_id")); - BytesReference bytes = BytesReference.bytes( + BytesReference bytes = BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("docs") .startObject() @@ -149,7 +150,7 @@ public void testSimulate() throws Exception { public void testBulkWithIngestFailures() throws Exception { createIndex("index"); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -200,7 +201,7 @@ public void testBulkWithIngestFailures() throws Exception { public void testBulkWithUpsert() throws Exception { createIndex("index"); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -235,7 +236,7 @@ public void testBulkWithUpsert() throws Exception { } public void test() throws Exception { - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -278,7 +279,7 @@ public void test() throws Exception { } public void testPutWithPipelineFactoryError() throws Exception { - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -303,7 +304,7 @@ public void testPutWithPipelineFactoryError() throws Exception { public void testWithDedicatedClusterManager() throws Exception { String clusterManagerOnlyNode = internalCluster().startClusterManagerOnlyNode(); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -340,7 +341,7 @@ public void testPipelineOriginHeader() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReference.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReferenceUtil.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -357,7 +358,7 @@ public void testPipelineOriginHeader() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReference.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReferenceUtil.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -373,7 +374,7 @@ public void testPipelineOriginHeader() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReference.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReferenceUtil.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } @@ -413,7 +414,7 @@ public void testPipelineProcessorOnFailure() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReference.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReferenceUtil.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -430,7 +431,7 @@ public void testPipelineProcessorOnFailure() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReference.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReferenceUtil.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -446,7 +447,7 @@ public void testPipelineProcessorOnFailure() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReference.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReferenceUtil.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java index a615cceffb5df..d5d4e246dae79 100644 --- a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java @@ -35,6 +35,7 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.node.NodeService; import org.opensearch.plugins.Plugin; @@ -58,7 +59,7 @@ public class IngestProcessorNotInstalledOnAllNodesIT extends OpenSearchIntegTest private volatile boolean installPlugin; public IngestProcessorNotInstalledOnAllNodesIT() throws IOException { - pipelineSource = BytesReference.bytes( + pipelineSource = BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("processors") .startObject() diff --git a/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java b/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java index c9d18e64ca038..93c2029615d45 100644 --- a/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java @@ -41,6 +41,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.search.fetch.subphase.FetchSourceContext; import org.opensearch.test.OpenSearchIntegTestCase; @@ -148,7 +149,7 @@ public void testThatMgetShouldWorkWithAliasRouting() throws IOException { @SuppressWarnings("unchecked") public void testThatSourceFilteringIsSupported() throws Exception { assertAcked(prepareCreate("test").addAlias(new Alias("alias"))); - BytesReference sourceBytesRef = BytesReference.bytes( + BytesReference sourceBytesRef = BytesReferenceUtil.bytes( jsonBuilder().startObject() .array("field", "1", "2") .startObject("included") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java index 9b40df5f19b9f..4cc509f3e8a0e 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java @@ -35,6 +35,7 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -69,7 +70,7 @@ public void testWrapperQueryIsRewritten() throws IOException { builder.endObject(); } builder.endObject(); - bytesReference = BytesReference.bytes(builder); + bytesReference = BytesReferenceUtil.bytes(builder); } FiltersAggregationBuilder builder = new FiltersAggregationBuilder( "titles", diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java index 7945f1f4274fb..9dd2bd7380877 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java @@ -44,6 +44,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.time.DateFormatter; import org.opensearch.common.time.DateUtils; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -892,7 +893,7 @@ public void testGetFieldsComplexField() throws Exception { ) .get(); - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("field1") .startObject() diff --git a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java index 3444ddbca9e65..1efc18c1e78a8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java @@ -57,6 +57,7 @@ import org.opensearch.common.geo.builders.PointBuilder; import org.opensearch.common.geo.builders.PolygonBuilder; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -242,7 +243,7 @@ public void testShapeRelations() throws Exception { .polygon( new PolygonBuilder(new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()) ); - BytesReference data = BytesReference.bytes(jsonBuilder().startObject().field("area", polygon).endObject()); + BytesReference data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", polygon).endObject()); client().prepareIndex("shapes").setId("1").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); @@ -306,7 +307,7 @@ public void testShapeRelations() throws Exception { new LineStringBuilder(new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()) ); - data = BytesReference.bytes(jsonBuilder().startObject().field("area", inverse).endObject()); + data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", inverse).endObject()); client().prepareIndex("shapes").setId("2").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); @@ -345,7 +346,7 @@ public void testShapeRelations() throws Exception { new CoordinatesBuilder().coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close() ); - data = BytesReference.bytes(jsonBuilder().startObject().field("area", builder).endObject()); + data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", builder).endObject()); client().prepareIndex("shapes").setId("1").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); @@ -358,7 +359,7 @@ public void testShapeRelations() throws Exception { ) ); - data = BytesReference.bytes(jsonBuilder().startObject().field("area", builder).endObject()); + data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", builder).endObject()); client().prepareIndex("shapes").setId("1").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java b/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java index a1ee8017894da..a552e0c1b253c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java @@ -41,9 +41,9 @@ import org.opensearch.action.search.ShardSearchFailure; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Priority; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -798,7 +798,7 @@ public void testRestartDataNodesDuringScrollSearch() throws Exception { private void assertToXContentResponse(ClearScrollResponse response, boolean succeed, int numFreed) throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); - Map map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map map = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); assertThat(map.get("succeeded"), is(succeed)); assertThat(map.get("num_freed"), equalTo(numFreed)); } diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java index ea1635b1d8053..e3741932cd674 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java @@ -42,6 +42,7 @@ import org.opensearch.action.ingest.GetPipelineResponse; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.IngestTestPlugin; @@ -104,7 +105,7 @@ public void testIncludeGlobalState() throws Exception { if (testPipeline) { logger.info("--> creating test pipeline"); - BytesReference pipelineSource = BytesReference.bytes( + BytesReference pipelineSource = BytesReferenceUtil.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") diff --git a/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java b/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java index 1c5d0c84a9a2f..3365aad425781 100644 --- a/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java @@ -34,7 +34,7 @@ import org.opensearch.action.update.UpdateRequestBuilder; import org.opensearch.action.update.UpdateResponse; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.test.OpenSearchIntegTestCase; @@ -323,7 +323,7 @@ private void updateAndCheckSource(long expectedSeqNo, long expectedVersion, XCon private void updateAndCheckSource(long expectedSeqNo, long expectedVersion, Boolean detectNoop, XContentBuilder xContentBuilder) { UpdateResponse updateResponse = update(detectNoop, expectedSeqNo, expectedVersion, xContentBuilder); - assertEquals(updateResponse.getGetResult().sourceRef().utf8ToString(), BytesReference.bytes(xContentBuilder).utf8ToString()); + assertEquals(updateResponse.getGetResult().sourceRef().utf8ToString(), BytesReferenceUtil.bytes(xContentBuilder).utf8ToString()); } private UpdateResponse update(Boolean detectNoop, long expectedSeqNo, long expectedVersion, XContentBuilder xContentBuilder) { diff --git a/server/src/main/java/org/opensearch/ExceptionsHelper.java b/server/src/main/java/org/opensearch/ExceptionsHelper.java index 111ac8e5ef276..f4cf68b203a3a 100644 --- a/server/src/main/java/org/opensearch/ExceptionsHelper.java +++ b/server/src/main/java/org/opensearch/ExceptionsHelper.java @@ -32,7 +32,6 @@ package org.opensearch; -import com.fasterxml.jackson.core.JsonParseException; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; @@ -40,10 +39,7 @@ import org.opensearch.common.CheckedRunnable; import org.opensearch.common.CheckedSupplier; import org.opensearch.common.Nullable; -import org.opensearch.common.compress.NotXContentException; -import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import org.opensearch.index.Index; -import org.opensearch.rest.RestStatus; import java.io.IOException; import java.util.ArrayList; @@ -81,23 +77,6 @@ public static OpenSearchException convertToOpenSearchException(Exception e) { return new OpenSearchException(e); } - public static RestStatus status(Throwable t) { - if (t != null) { - if (t instanceof OpenSearchException) { - return ((OpenSearchException) t).status(); - } else if (t instanceof IllegalArgumentException) { - return RestStatus.BAD_REQUEST; - } else if (t instanceof JsonParseException) { - return RestStatus.BAD_REQUEST; - } else if (t instanceof OpenSearchRejectedExecutionException) { - return RestStatus.TOO_MANY_REQUESTS; - } else if (t instanceof NotXContentException) { - return RestStatus.BAD_REQUEST; - } - } - return RestStatus.INTERNAL_SERVER_ERROR; - } - public static String formatStackTrace(final StackTraceElement[] stackTrace) { return Arrays.stream(stackTrace).skip(1).map(e -> "\tat " + e).collect(Collectors.joining("\n")); } diff --git a/server/src/main/java/org/opensearch/OpenSearchException.java b/server/src/main/java/org/opensearch/OpenSearchException.java index 5d258b338f57e..9ee67964ff3cd 100644 --- a/server/src/main/java/org/opensearch/OpenSearchException.java +++ b/server/src/main/java/org/opensearch/OpenSearchException.java @@ -38,28 +38,15 @@ import org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException; import org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException; import org.opensearch.cluster.service.ClusterManagerThrottlingException; -import org.opensearch.common.CheckedFunction; -import org.opensearch.common.collect.Tuple; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.io.stream.Writeable; -import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.index.Index; -import org.opensearch.index.shard.ShardId; -import org.opensearch.rest.RestStatus; +import org.opensearch.index.snapshots.IndexShardSnapshotException; import org.opensearch.search.aggregations.MultiBucketConsumerService; import org.opensearch.search.pipeline.SearchPipelineProcessingException; import org.opensearch.snapshots.SnapshotInUseDeletionException; import org.opensearch.transport.TcpTransport; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; import static org.opensearch.BaseOpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; import static org.opensearch.Version.V_2_1_0; @@ -68,16 +55,13 @@ import static org.opensearch.Version.V_2_6_0; import static org.opensearch.Version.V_2_7_0; import static org.opensearch.Version.V_3_0_0; -import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_UUID_NA_VALUE; -import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; -import static org.opensearch.common.xcontent.XContentParserUtils.ensureFieldName; /** * A base class for all opensearch exceptions. * * @opensearch.internal */ -public class OpenSearchException extends BaseOpenSearchException implements Writeable { +public class OpenSearchException extends BaseOpenSearchException { /** * Setting a higher base exception id to avoid conflicts. @@ -86,15 +70,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ static { registerExceptionHandle( - new OpenSearchExceptionHandle( - org.opensearch.index.snapshots.IndexShardSnapshotFailedException.class, - org.opensearch.index.snapshots.IndexShardSnapshotFailedException::new, - 0, - UNKNOWN_VERSION_ADDED - ) - ); - registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.dfs.DfsPhaseExecutionException.class, org.opensearch.search.dfs.DfsPhaseExecutionException::new, 1, @@ -102,7 +78,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.common.util.CancellableThreads.ExecutionCancelledException.class, org.opensearch.common.util.CancellableThreads.ExecutionCancelledException::new, 2, @@ -110,7 +86,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.discovery.ClusterManagerNotDiscoveredException.class, org.opensearch.discovery.ClusterManagerNotDiscoveredException::new, 3, @@ -118,7 +94,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.OpenSearchSecurityException.class, org.opensearch.OpenSearchSecurityException::new, 4, @@ -126,7 +102,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardRestoreException.class, org.opensearch.index.snapshots.IndexShardRestoreException::new, 5, @@ -134,7 +110,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.IndexClosedException.class, org.opensearch.indices.IndexClosedException::new, 6, @@ -142,7 +118,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.http.BindHttpException.class, org.opensearch.http.BindHttpException::new, 7, @@ -150,7 +126,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.search.ReduceSearchPhaseException.class, org.opensearch.action.search.ReduceSearchPhaseException::new, 8, @@ -158,7 +134,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.node.NodeClosedException.class, org.opensearch.node.NodeClosedException::new, 9, @@ -166,7 +142,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.SnapshotFailedEngineException.class, org.opensearch.index.engine.SnapshotFailedEngineException::new, 10, @@ -174,7 +150,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.ShardNotFoundException.class, org.opensearch.index.shard.ShardNotFoundException::new, 11, @@ -182,7 +158,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.ConnectTransportException.class, org.opensearch.transport.ConnectTransportException::new, 12, @@ -190,7 +166,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.NotSerializableTransportException.class, org.opensearch.transport.NotSerializableTransportException::new, 13, @@ -198,7 +174,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.ResponseHandlerFailureTransportException.class, org.opensearch.transport.ResponseHandlerFailureTransportException::new, 14, @@ -206,7 +182,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.IndexCreationException.class, org.opensearch.indices.IndexCreationException::new, 15, @@ -214,7 +190,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.IndexNotFoundException.class, org.opensearch.index.IndexNotFoundException::new, 16, @@ -222,7 +198,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.routing.IllegalShardRoutingStateException.class, org.opensearch.cluster.routing.IllegalShardRoutingStateException::new, 17, @@ -230,7 +206,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException.class, org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException::new, 18, @@ -238,7 +214,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.ResourceNotFoundException.class, org.opensearch.ResourceNotFoundException::new, 19, @@ -246,7 +222,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.ActionTransportException.class, org.opensearch.transport.ActionTransportException::new, 20, @@ -254,7 +230,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.OpenSearchGenerationException.class, org.opensearch.OpenSearchGenerationException::new, 21, @@ -263,7 +239,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 22 was CreateFailedEngineException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardStartedException.class, org.opensearch.index.shard.IndexShardStartedException::new, 23, @@ -271,7 +247,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.SearchContextMissingException.class, org.opensearch.search.SearchContextMissingException::new, 24, @@ -279,7 +255,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.script.GeneralScriptException.class, org.opensearch.script.GeneralScriptException::new, 25, @@ -288,7 +264,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 26 was BatchOperationException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotCreationException.class, org.opensearch.snapshots.SnapshotCreationException::new, 27, @@ -297,7 +273,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 28 was DeleteFailedEngineException, deprecated in 6.0, removed in 7.0 registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.DocumentMissingException.class, org.opensearch.index.engine.DocumentMissingException::new, 29, @@ -305,7 +281,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotException.class, org.opensearch.snapshots.SnapshotException::new, 30, @@ -313,7 +289,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.InvalidAliasNameException.class, org.opensearch.indices.InvalidAliasNameException::new, 31, @@ -321,7 +297,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.InvalidIndexNameException.class, org.opensearch.indices.InvalidIndexNameException::new, 32, @@ -329,7 +305,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.IndexPrimaryShardNotAllocatedException.class, org.opensearch.indices.IndexPrimaryShardNotAllocatedException::new, 33, @@ -337,7 +313,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.TransportException.class, org.opensearch.transport.TransportException::new, 34, @@ -345,7 +321,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.OpenSearchParseException.class, org.opensearch.OpenSearchParseException::new, 35, @@ -353,7 +329,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.SearchException.class, org.opensearch.search.SearchException::new, 36, @@ -361,7 +337,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.mapper.MapperException.class, org.opensearch.index.mapper.MapperException::new, 37, @@ -369,7 +345,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.InvalidTypeNameException.class, org.opensearch.indices.InvalidTypeNameException::new, 38, @@ -377,7 +353,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotRestoreException.class, org.opensearch.snapshots.SnapshotRestoreException::new, 39, @@ -385,15 +361,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( - org.opensearch.common.ParsingException.class, - org.opensearch.common.ParsingException::new, - 40, - UNKNOWN_VERSION_ADDED - ) - ); - registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardClosedException.class, org.opensearch.index.shard.IndexShardClosedException::new, 41, @@ -401,7 +369,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.recovery.RecoverFilesRecoveryException.class, org.opensearch.indices.recovery.RecoverFilesRecoveryException::new, 42, @@ -409,7 +377,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.translog.TruncatedTranslogException.class, org.opensearch.index.translog.TruncatedTranslogException::new, 43, @@ -417,7 +385,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.recovery.RecoveryFailedException.class, org.opensearch.indices.recovery.RecoveryFailedException::new, 44, @@ -425,7 +393,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRelocatedException.class, org.opensearch.index.shard.IndexShardRelocatedException::new, 45, @@ -433,7 +401,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.NodeShouldNotConnectException.class, org.opensearch.transport.NodeShouldNotConnectException::new, 46, @@ -442,7 +410,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 47 used to be for IndexTemplateAlreadyExistsException which was deprecated in 5.1 removed in 6.0 registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.translog.TranslogCorruptedException.class, org.opensearch.index.translog.TranslogCorruptedException::new, 48, @@ -450,7 +418,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.block.ClusterBlockException.class, org.opensearch.cluster.block.ClusterBlockException::new, 49, @@ -458,7 +426,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.fetch.FetchPhaseExecutionException.class, org.opensearch.search.fetch.FetchPhaseExecutionException::new, 50, @@ -467,7 +435,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 51 used to be for IndexShardAlreadyExistsException which was deprecated in 5.1 removed in 6.0 registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.VersionConflictEngineException.class, org.opensearch.index.engine.VersionConflictEngineException::new, 52, @@ -475,7 +443,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.EngineException.class, org.opensearch.index.engine.EngineException::new, 53, @@ -484,7 +452,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 54 was DocumentAlreadyExistsException, which is superseded by VersionConflictEngineException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.NoSuchNodeException.class, org.opensearch.action.NoSuchNodeException::new, 55, @@ -492,7 +460,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.common.settings.SettingsException.class, org.opensearch.common.settings.SettingsException::new, 56, @@ -500,7 +468,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.IndexTemplateMissingException.class, org.opensearch.indices.IndexTemplateMissingException::new, 57, @@ -508,7 +476,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.SendRequestTransportException.class, org.opensearch.transport.SendRequestTransportException::new, 58, @@ -519,15 +487,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ // 60 used to be for EarlyTerminationException // 61 used to be for RoutingValidationException registerExceptionHandle( - new OpenSearchExceptionHandle( - org.opensearch.common.io.stream.NotSerializableExceptionWrapper.class, - org.opensearch.common.io.stream.NotSerializableExceptionWrapper::new, - 62, - UNKNOWN_VERSION_ADDED - ) - ); - registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.AliasFilterParsingException.class, org.opensearch.indices.AliasFilterParsingException::new, 63, @@ -536,7 +496,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 64 was DeleteByQueryFailedEngineException, which was removed in 5.0 registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.gateway.GatewayException.class, org.opensearch.gateway.GatewayException::new, 65, @@ -544,7 +504,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardNotRecoveringException.class, org.opensearch.index.shard.IndexShardNotRecoveringException::new, 66, @@ -552,7 +512,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.http.HttpException.class, org.opensearch.http.HttpException::new, 67, @@ -560,10 +520,10 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle(OpenSearchException.class, OpenSearchException::new, 68, UNKNOWN_VERSION_ADDED) + new BaseOpenSearchExceptionHandle(OpenSearchException.class, OpenSearchException::new, 68, UNKNOWN_VERSION_ADDED) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotMissingException.class, org.opensearch.snapshots.SnapshotMissingException::new, 69, @@ -571,7 +531,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.PrimaryMissingActionException.class, org.opensearch.action.PrimaryMissingActionException::new, 70, @@ -579,7 +539,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.SearchParseException.class, org.opensearch.search.SearchParseException::new, 72, @@ -587,7 +547,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.FailedNodeException.class, org.opensearch.action.FailedNodeException::new, 71, @@ -595,7 +555,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.ConcurrentSnapshotExecutionException.class, org.opensearch.snapshots.ConcurrentSnapshotExecutionException::new, 73, @@ -603,7 +563,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.common.blobstore.BlobStoreException.class, org.opensearch.common.blobstore.BlobStoreException::new, 74, @@ -611,7 +571,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.IncompatibleClusterStateVersionException.class, org.opensearch.cluster.IncompatibleClusterStateVersionException::new, 75, @@ -619,7 +579,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.RecoveryEngineException.class, org.opensearch.index.engine.RecoveryEngineException::new, 76, @@ -627,7 +587,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.common.util.concurrent.UncategorizedExecutionException.class, org.opensearch.common.util.concurrent.UncategorizedExecutionException::new, 77, @@ -635,7 +595,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.TimestampParsingException.class, org.opensearch.action.TimestampParsingException::new, 78, @@ -643,7 +603,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.RoutingMissingException.class, org.opensearch.action.RoutingMissingException::new, 79, @@ -652,7 +612,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 80 was IndexFailedEngineException, deprecated in 6.0, removed in 7.0 registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardRestoreFailedException.class, org.opensearch.index.snapshots.IndexShardRestoreFailedException::new, 81, @@ -660,7 +620,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.repositories.RepositoryException.class, org.opensearch.repositories.RepositoryException::new, 82, @@ -668,7 +628,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.ReceiveTimeoutTransportException.class, org.opensearch.transport.ReceiveTimeoutTransportException::new, 83, @@ -676,7 +636,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.NodeDisconnectedException.class, org.opensearch.transport.NodeDisconnectedException::new, 84, @@ -685,7 +645,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 85 used to be for AlreadyExpiredException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.aggregations.AggregationExecutionException.class, org.opensearch.search.aggregations.AggregationExecutionException::new, 86, @@ -694,7 +654,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 87 used to be for MergeMappingException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.InvalidIndexTemplateException.class, org.opensearch.indices.InvalidIndexTemplateException::new, 88, @@ -702,7 +662,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.RefreshFailedEngineException.class, org.opensearch.index.engine.RefreshFailedEngineException::new, 90, @@ -710,7 +670,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.aggregations.AggregationInitializationException.class, org.opensearch.search.aggregations.AggregationInitializationException::new, 91, @@ -718,7 +678,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.recovery.DelayRecoveryException.class, org.opensearch.indices.recovery.DelayRecoveryException::new, 92, @@ -727,7 +687,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 93 used to be for IndexWarmerMissingException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.client.transport.NoNodeAvailableException.class, org.opensearch.client.transport.NoNodeAvailableException::new, 94, @@ -735,7 +695,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.InvalidSnapshotNameException.class, org.opensearch.snapshots.InvalidSnapshotNameException::new, 96, @@ -743,7 +703,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IllegalIndexShardStateException.class, org.opensearch.index.shard.IllegalIndexShardStateException::new, 97, @@ -751,15 +711,15 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( - org.opensearch.index.snapshots.IndexShardSnapshotException.class, - org.opensearch.index.snapshots.IndexShardSnapshotException::new, + new BaseOpenSearchExceptionHandle( + IndexShardSnapshotException.class, + IndexShardSnapshotException::new, 98, UNKNOWN_VERSION_ADDED ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardNotStartedException.class, org.opensearch.index.shard.IndexShardNotStartedException::new, 99, @@ -767,7 +727,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.search.SearchPhaseExecutionException.class, org.opensearch.action.search.SearchPhaseExecutionException::new, 100, @@ -775,7 +735,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.ActionNotFoundTransportException.class, org.opensearch.transport.ActionNotFoundTransportException::new, 101, @@ -783,7 +743,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.TransportSerializationException.class, org.opensearch.transport.TransportSerializationException::new, 102, @@ -791,7 +751,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.RemoteTransportException.class, org.opensearch.transport.RemoteTransportException::new, 103, @@ -799,7 +759,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.EngineCreationFailureException.class, org.opensearch.index.engine.EngineCreationFailureException::new, 104, @@ -807,7 +767,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.routing.RoutingException.class, org.opensearch.cluster.routing.RoutingException::new, 105, @@ -815,7 +775,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRecoveryException.class, org.opensearch.index.shard.IndexShardRecoveryException::new, 106, @@ -823,7 +783,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.repositories.RepositoryMissingException.class, org.opensearch.repositories.RepositoryMissingException::new, 107, @@ -831,7 +791,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.DocumentSourceMissingException.class, org.opensearch.index.engine.DocumentSourceMissingException::new, 109, @@ -840,7 +800,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 110 used to be FlushNotAllowedEngineException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.common.settings.NoClassSettingsException.class, org.opensearch.common.settings.NoClassSettingsException::new, 111, @@ -848,7 +808,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.BindTransportException.class, org.opensearch.transport.BindTransportException::new, 112, @@ -856,7 +816,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.rest.action.admin.indices.AliasesNotFoundException.class, org.opensearch.rest.action.admin.indices.AliasesNotFoundException::new, 113, @@ -864,7 +824,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRecoveringException.class, org.opensearch.index.shard.IndexShardRecoveringException::new, 114, @@ -872,7 +832,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.translog.TranslogException.class, org.opensearch.index.translog.TranslogException::new, 115, @@ -880,7 +840,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException.class, org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException::new, 116, @@ -888,7 +848,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( ReplicationOperation.RetryOnPrimaryException.class, ReplicationOperation.RetryOnPrimaryException::new, 117, @@ -896,7 +856,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.OpenSearchTimeoutException.class, org.opensearch.OpenSearchTimeoutException::new, 118, @@ -904,7 +864,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.query.QueryPhaseExecutionException.class, org.opensearch.search.query.QueryPhaseExecutionException::new, 119, @@ -912,7 +872,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.repositories.RepositoryVerificationException.class, org.opensearch.repositories.RepositoryVerificationException::new, 120, @@ -920,7 +880,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.aggregations.InvalidAggregationPathException.class, org.opensearch.search.aggregations.InvalidAggregationPathException::new, 121, @@ -929,7 +889,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 123 used to be IndexAlreadyExistsException and was renamed registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( ResourceAlreadyExistsException.class, ResourceAlreadyExistsException::new, 123, @@ -938,7 +898,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 124 used to be Script.ScriptParseException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( TcpTransport.HttpRequestOnTransportException.class, TcpTransport.HttpRequestOnTransportException::new, 125, @@ -946,7 +906,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.mapper.MapperParsingException.class, org.opensearch.index.mapper.MapperParsingException::new, 126, @@ -955,7 +915,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 127 used to be org.opensearch.search.SearchContextException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.search.builder.SearchSourceBuilderException.class, org.opensearch.search.builder.SearchSourceBuilderException::new, 128, @@ -964,7 +924,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 129 was EngineClosedException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.NoShardAvailableActionException.class, org.opensearch.action.NoShardAvailableActionException::new, 130, @@ -972,7 +932,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.UnavailableShardsException.class, org.opensearch.action.UnavailableShardsException::new, 131, @@ -980,7 +940,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.engine.FlushFailedEngineException.class, org.opensearch.index.engine.FlushFailedEngineException::new, 132, @@ -988,7 +948,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.common.breaker.CircuitBreakingException.class, org.opensearch.common.breaker.CircuitBreakingException::new, 133, @@ -996,7 +956,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.NodeNotConnectedException.class, org.opensearch.transport.NodeNotConnectedException::new, 134, @@ -1004,7 +964,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.mapper.StrictDynamicMappingException.class, org.opensearch.index.mapper.StrictDynamicMappingException::new, 135, @@ -1012,7 +972,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException.class, org.opensearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException::new, 136, @@ -1020,7 +980,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.TypeMissingException.class, org.opensearch.indices.TypeMissingException::new, 137, @@ -1028,7 +988,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.coordination.FailedToCommitClusterStateException.class, org.opensearch.cluster.coordination.FailedToCommitClusterStateException::new, 140, @@ -1036,7 +996,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.query.QueryShardException.class, org.opensearch.index.query.QueryShardException::new, 141, @@ -1044,7 +1004,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( ShardStateAction.NoLongerPrimaryShardException.class, ShardStateAction.NoLongerPrimaryShardException::new, 142, @@ -1052,7 +1012,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.script.ScriptException.class, org.opensearch.script.ScriptException::new, 143, @@ -1060,7 +1020,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.NotClusterManagerException.class, org.opensearch.cluster.NotClusterManagerException::new, 144, @@ -1068,7 +1028,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.OpenSearchStatusException.class, org.opensearch.OpenSearchStatusException::new, 145, @@ -1076,7 +1036,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.tasks.TaskCancelledException.class, org.opensearch.tasks.TaskCancelledException::new, 146, @@ -1084,7 +1044,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.env.ShardLockObtainFailedException.class, org.opensearch.env.ShardLockObtainFailedException::new, 147, @@ -1093,7 +1053,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ); // 148 was UnknownNamedObjectException registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( MultiBucketConsumerService.TooManyBucketsException.class, MultiBucketConsumerService.TooManyBucketsException::new, 149, @@ -1101,7 +1061,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.coordination.CoordinationStateRejectedException.class, org.opensearch.cluster.coordination.CoordinationStateRejectedException::new, 150, @@ -1109,7 +1069,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotInProgressException.class, org.opensearch.snapshots.SnapshotInProgressException::new, 151, @@ -1117,7 +1077,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.NoSuchRemoteClusterException.class, org.opensearch.transport.NoSuchRemoteClusterException::new, 152, @@ -1125,7 +1085,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException.class, org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException::new, 153, @@ -1133,7 +1093,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseNotFoundException.class, org.opensearch.index.seqno.RetentionLeaseNotFoundException::new, 154, @@ -1141,7 +1101,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.ShardNotInPrimaryModeException.class, org.opensearch.index.shard.ShardNotInPrimaryModeException::new, 155, @@ -1149,7 +1109,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException.class, org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException::new, 156, @@ -1157,7 +1117,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.ingest.IngestProcessorException.class, org.opensearch.ingest.IngestProcessorException::new, 157, @@ -1165,7 +1125,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.recovery.PeerRecoveryNotFound.class, org.opensearch.indices.recovery.PeerRecoveryNotFound::new, 158, @@ -1173,7 +1133,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.coordination.NodeHealthCheckFailureException.class, org.opensearch.cluster.coordination.NodeHealthCheckFailureException::new, 159, @@ -1181,7 +1141,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.transport.NoSeedNodeLeftException.class, org.opensearch.transport.NoSeedNodeLeftException::new, 160, @@ -1189,7 +1149,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.indices.replication.common.ReplicationFailedException.class, org.opensearch.indices.replication.common.ReplicationFailedException::new, 161, @@ -1197,7 +1157,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.index.shard.PrimaryShardClosedException.class, org.opensearch.index.shard.PrimaryShardClosedException::new, 162, @@ -1205,7 +1165,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.decommission.DecommissioningFailedException.class, org.opensearch.cluster.decommission.DecommissioningFailedException::new, 163, @@ -1213,7 +1173,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.decommission.NodeDecommissionedException.class, org.opensearch.cluster.decommission.NodeDecommissionedException::new, 164, @@ -1221,7 +1181,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( ClusterManagerThrottlingException.class, ClusterManagerThrottlingException::new, 165, @@ -1229,7 +1189,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( SnapshotInUseDeletionException.class, SnapshotInUseDeletionException::new, 166, @@ -1237,7 +1197,7 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( UnsupportedWeightedRoutingStateException.class, UnsupportedWeightedRoutingStateException::new, 167, @@ -1245,19 +1205,21 @@ public class OpenSearchException extends BaseOpenSearchException implements Writ ) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( PreferenceBasedSearchNotAllowedException.class, PreferenceBasedSearchNotAllowedException::new, 168, V_2_6_0 ) ); - registerExceptionHandle(new OpenSearchExceptionHandle(NodeWeighedAwayException.class, NodeWeighedAwayException::new, 169, V_2_6_0)); registerExceptionHandle( - new OpenSearchExceptionHandle(SearchPipelineProcessingException.class, SearchPipelineProcessingException::new, 170, V_2_7_0) + new BaseOpenSearchExceptionHandle(NodeWeighedAwayException.class, NodeWeighedAwayException::new, 169, V_2_6_0) + ); + registerExceptionHandle( + new BaseOpenSearchExceptionHandle(SearchPipelineProcessingException.class, SearchPipelineProcessingException::new, 170, V_2_7_0) ); registerExceptionHandle( - new OpenSearchExceptionHandle( + new BaseOpenSearchExceptionHandle( org.opensearch.cluster.block.IndexCreateBlockException.class, org.opensearch.cluster.block.IndexCreateBlockException::new, CUSTOM_ELASTICSEARCH_EXCEPTIONS_BASE_ID + 1, @@ -1302,321 +1264,20 @@ public OpenSearchException(String msg, Throwable cause, Object... args) { } public OpenSearchException(StreamInput in) throws IOException { - super(in.readOptionalString(), in.readException()); - readStackTrace(this, in); - headers.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString)); - metadata.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString)); - } - - /** - * Returns the rest status code associated with this exception. - */ - public RestStatus status() { - Throwable cause = unwrapCause(); - if (cause == this) { - return RestStatus.INTERNAL_SERVER_ERROR; - } else { - return ExceptionsHelper.status(cause); - } + super(in); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeOptionalString(this.getMessage()); - out.writeException(this.getCause()); - writeStackTraces(this, out, StreamOutput::writeException); - out.writeMapOfLists(headers, StreamOutput::writeString, StreamOutput::writeString); - out.writeMapOfLists(metadata, StreamOutput::writeString, StreamOutput::writeString); + super.writeTo(out); } /** * Returns true iff the given class is a registered for an exception to be read. - */ - public static boolean isRegistered(final Class exception, Version version) { - return OpenSearchExceptionHandleRegistry.isRegistered(exception, version); - } - - static Set> getRegisteredKeys() { // for testing - return OpenSearchExceptionHandleRegistry.getRegisteredKeys(); - } - - /** - * Returns the serialization id the given exception. - */ - public static int getId(final Class exception) { - return OpenSearchExceptionHandleRegistry.getId(exception); - } - - /** - * Generate a {@link OpenSearchException} from a {@link XContentParser}. This does not - * return the original exception type (ie NodeClosedException for example) but just wraps - * the type, the reason and the cause of the exception. It also recursively parses the - * tree structure of the cause, returning it as a tree structure of {@link OpenSearchException} - * instances. - */ - public static OpenSearchException fromXContent(XContentParser parser) throws IOException { - XContentParser.Token token = parser.nextToken(); - ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - return innerFromXContent(parser, false); - } - - public static OpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException { - XContentParser.Token token = parser.currentToken(); - ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - - String type = null, reason = null, stack = null; - OpenSearchException cause = null; - Map> metadata = new HashMap<>(); - Map> headers = new HashMap<>(); - List rootCauses = new ArrayList<>(); - List suppressed = new ArrayList<>(); - - for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) { - String currentFieldName = parser.currentName(); - token = parser.nextToken(); - - if (token.isValue()) { - if (BaseExceptionsHelper.TYPE.equals(currentFieldName)) { - type = parser.text(); - } else if (BaseExceptionsHelper.REASON.equals(currentFieldName)) { - reason = parser.text(); - } else if (BaseExceptionsHelper.STACK_TRACE.equals(currentFieldName)) { - stack = parser.text(); - } else if (token == XContentParser.Token.VALUE_STRING) { - metadata.put(currentFieldName, Collections.singletonList(parser.text())); - } - } else if (token == XContentParser.Token.START_OBJECT) { - if (BaseExceptionsHelper.CAUSED_BY.equals(currentFieldName)) { - cause = fromXContent(parser); - } else if (BaseExceptionsHelper.HEADER.equals(currentFieldName)) { - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else { - List values = headers.getOrDefault(currentFieldName, new ArrayList<>()); - if (token == XContentParser.Token.VALUE_STRING) { - values.add(parser.text()); - } else if (token == XContentParser.Token.START_ARRAY) { - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (token == XContentParser.Token.VALUE_STRING) { - values.add(parser.text()); - } else { - parser.skipChildren(); - } - } - } else if (token == XContentParser.Token.START_OBJECT) { - parser.skipChildren(); - } - headers.put(currentFieldName, values); - } - } - } else { - // Any additional metadata object added by the metadataToXContent method is ignored - // and skipped, so that the parser does not fail on unknown fields. The parser only - // support metadata key-pairs and metadata arrays of values. - parser.skipChildren(); - } - } else if (token == XContentParser.Token.START_ARRAY) { - if (parseRootCauses && ROOT_CAUSE.equals(currentFieldName)) { - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - rootCauses.add(fromXContent(parser)); - } - } else if (BaseExceptionsHelper.SUPPRESSED.match(currentFieldName, parser.getDeprecationHandler())) { - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - suppressed.add(fromXContent(parser)); - } - } else { - // Parse the array and add each item to the corresponding list of metadata. - // Arrays of objects are not supported yet and just ignored and skipped. - List values = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (token == XContentParser.Token.VALUE_STRING) { - values.add(parser.text()); - } else { - parser.skipChildren(); - } - } - if (values.size() > 0) { - if (metadata.containsKey(currentFieldName)) { - values.addAll(metadata.get(currentFieldName)); - } - metadata.put(currentFieldName, values); - } - } - } - } - - OpenSearchException e = new OpenSearchException(buildMessage(type, reason, stack), cause); - for (Map.Entry> entry : metadata.entrySet()) { - // subclasses can print out additional metadata through the metadataToXContent method. Simple key-value pairs will be - // parsed back and become part of this metadata set, while objects and arrays are not supported when parsing back. - // Those key-value pairs become part of the metadata set and inherit the "opensearch." prefix as that is currently required - // by addMetadata. The prefix will get stripped out when printing metadata out so it will be effectively invisible. - // TODO move subclasses that print out simple metadata to using addMetadata directly and support also numbers and booleans. - // TODO rename metadataToXContent and have only SearchPhaseExecutionException use it, which prints out complex objects - e.addMetadata(BaseExceptionsHelper.OPENSEARCH_PREFIX_KEY + entry.getKey(), entry.getValue()); - } - for (Map.Entry> header : headers.entrySet()) { - e.addHeader(header.getKey(), header.getValue()); - } - - // Adds root causes as suppressed exception. This way they are not lost - // after parsing and can be retrieved using getSuppressed() method. - for (OpenSearchException rootCause : rootCauses) { - e.addSuppressed(rootCause); - } - for (OpenSearchException s : suppressed) { - e.addSuppressed(s); - } - return e; - } - - /** - * Parses the output of {@link #generateFailureXContent(XContentBuilder, Params, Exception, boolean)} - */ - public static OpenSearchException failureFromXContent(XContentParser parser) throws IOException { - XContentParser.Token token = parser.currentToken(); - ensureFieldName(parser, token, ERROR); - - token = parser.nextToken(); - if (token.isValue()) { - return new OpenSearchException(buildMessage("exception", parser.text(), null)); - } - - ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); - token = parser.nextToken(); - - // Root causes are parsed in the innerFromXContent() and are added as suppressed exceptions. - return innerFromXContent(parser, true); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - if (metadata.containsKey(INDEX_METADATA_KEY)) { - builder.append(getIndex()); - if (metadata.containsKey(SHARD_METADATA_KEY)) { - builder.append('[').append(getShardId()).append(']'); - } - builder.append(' '); - } - return builder.append(BaseExceptionsHelper.detailedMessage(this).trim()).toString(); - } - - /** - * Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and - * adds it to the given exception. - */ - public static T readStackTrace(T throwable, StreamInput in) throws IOException { - throwable.setStackTrace(in.readArray(i -> { - final String declaringClasss = i.readString(); - final String fileName = i.readOptionalString(); - final String methodName = i.readString(); - final int lineNumber = i.readVInt(); - return new StackTraceElement(declaringClasss, methodName, fileName, lineNumber); - }, StackTraceElement[]::new)); - - int numSuppressed = in.readVInt(); - for (int i = 0; i < numSuppressed; i++) { - throwable.addSuppressed(in.readException()); - } - return throwable; - } - - /** - * Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream. - */ - public static T writeStackTraces(T throwable, StreamOutput out, Writer exceptionWriter) - throws IOException { - out.writeArray((o, v) -> { - o.writeString(v.getClassName()); - o.writeOptionalString(v.getFileName()); - o.writeString(v.getMethodName()); - o.writeVInt(v.getLineNumber()); - }, throwable.getStackTrace()); - out.writeArray(exceptionWriter, throwable.getSuppressed()); - return throwable; - } - - /** - * This is the list of Exceptions OpenSearch can throw over the wire or save into a corruption marker. Each value in the enum is a - * single exception tying the Class to an id for use of the encode side and the id back to a constructor for use on the decode side. As - * such its ok if the exceptions to change names so long as their constructor can still read the exception. Each exception is listed - * in id order below. If you want to remove an exception leave a tombstone comment and mark the id as null in - * ExceptionSerializationTests.testIds.ids. - */ - protected static class OpenSearchExceptionHandle extends BaseOpenSearchExceptionHandle { - OpenSearchExceptionHandle( - final Class exceptionClass, - final CheckedFunction constructor, - final int id, - final Version versionAdded - ) { - super(exceptionClass, constructor, id, versionAdded); - OpenSearchExceptionHandleRegistry.registerExceptionHandle(this); - } - } - - /** - * Returns an array of all registered handle IDs. These are the IDs for every registered - * exception. - * - * @return an array of all registered handle IDs - */ - static int[] ids() { - return OpenSearchExceptionHandleRegistry.ids().stream().mapToInt(i -> i).toArray(); - } - - /** - * Returns an array of all registered pairs of handle IDs and exception classes. These pairs are - * provided for every registered exception. * - * @return an array of all registered pairs of handle IDs and exception classes + * note: this "override" method is provided to ensure static registration of the exceptions above */ - static Tuple>[] classes() { - final Tuple>[] ts = OpenSearchExceptionHandleRegistry.handles() - .stream() - .map(h -> Tuple.tuple(h.id, h.exceptionClass)) - .toArray(Tuple[]::new); - return ts; - } - - public Index getIndex() { - List index = getMetadata(INDEX_METADATA_KEY); - if (index != null && index.isEmpty() == false) { - List index_uuid = getMetadata(INDEX_METADATA_KEY_UUID); - return new Index(index.get(0), index_uuid.get(0)); - } - - return null; - } - - public ShardId getShardId() { - List shard = getMetadata(SHARD_METADATA_KEY); - if (shard != null && shard.isEmpty() == false) { - return new ShardId(getIndex(), Integer.parseInt(shard.get(0))); - } - return null; - } - - public void setIndex(Index index) { - if (index != null) { - addMetadata(INDEX_METADATA_KEY, index.getName()); - addMetadata(INDEX_METADATA_KEY_UUID, index.getUUID()); - } - } - - public void setIndex(String index) { - if (index != null) { - setIndex(new Index(index, INDEX_UUID_NA_VALUE)); - } - } - - public void setShard(ShardId shardId) { - if (shardId != null) { - setIndex(shardId.getIndex()); - addMetadata(SHARD_METADATA_KEY, Integer.toString(shardId.id())); - } + public static boolean isRegistered(final Class exception, Version version) { + return BaseOpenSearchException.isRegistered(exception, version); } - } diff --git a/server/src/main/java/org/opensearch/OpenSearchSecurityException.java b/server/src/main/java/org/opensearch/OpenSearchSecurityException.java index 6f725573e71ce..c663dc0822cfd 100644 --- a/server/src/main/java/org/opensearch/OpenSearchSecurityException.java +++ b/server/src/main/java/org/opensearch/OpenSearchSecurityException.java @@ -53,7 +53,7 @@ public OpenSearchSecurityException(String msg, RestStatus status, Throwable caus * Build the exception with the status derived from the cause. */ public OpenSearchSecurityException(String msg, Exception cause, Object... args) { - this(msg, ExceptionsHelper.status(cause), cause, args); + this(msg, BaseExceptionsHelper.status(cause), cause, args); } /** diff --git a/server/src/main/java/org/opensearch/action/TaskOperationFailure.java b/server/src/main/java/org/opensearch/action/TaskOperationFailure.java index e1cf77fb3d530..41b4203201575 100644 --- a/server/src/main/java/org/opensearch/action/TaskOperationFailure.java +++ b/server/src/main/java/org/opensearch/action/TaskOperationFailure.java @@ -33,8 +33,8 @@ package org.opensearch.action; import org.opensearch.BaseExceptionsHelper; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; -import org.opensearch.ExceptionsHelper; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -76,7 +76,7 @@ public final class TaskOperationFailure implements Writeable, ToXContentFragment int i = 0; String nodeId = (String) constructorObjects[i++]; long taskId = (long) constructorObjects[i++]; - OpenSearchException reason = (OpenSearchException) constructorObjects[i]; + BaseOpenSearchException reason = (BaseOpenSearchException) constructorObjects[i]; return new TaskOperationFailure(nodeId, taskId, reason); } ); @@ -91,7 +91,7 @@ public TaskOperationFailure(String nodeId, long taskId, Exception e) { this.nodeId = nodeId; this.taskId = taskId; this.reason = e; - status = ExceptionsHelper.status(e); + status = BaseExceptionsHelper.status(e); } /** diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java index 738c8a9d514c9..a7385c57d4b91 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java @@ -18,6 +18,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.DeprecationHandler; @@ -89,7 +90,7 @@ public ClusterDeleteWeightedRoutingRequest source(Map source) { } XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - setRequestBody(BytesReference.bytes(builder), builder.contentType()); + setRequestBody(BytesReferenceUtil.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java index fe95b614a02d1..2a3dc4053f82a 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java @@ -19,6 +19,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.DeprecationHandler; @@ -86,7 +87,7 @@ public void setWeightedRouting(Map source) { } XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - setWeightedRouting(BytesReference.bytes(builder), builder.contentType()); + setWeightedRouting(BytesReferenceUtil.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java index 0226b20b5bf34..21fb7a49d0dd3 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java @@ -39,10 +39,10 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; @@ -182,7 +182,7 @@ public static int metadataSize(Map userMetadata) { } try (XContentBuilder builder = XContentFactory.jsonBuilder()) { builder.value(userMetadata); - int size = BytesReference.bytes(builder).length(); + int size = BytesReferenceUtil.bytes(builder).length(); return size; } catch (IOException e) { // This should not be possible as we are just rendering the xcontent in memory diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java index b9c11a003c459..45bae32f8c0c6 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java @@ -48,6 +48,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -315,7 +316,7 @@ public CreateIndexRequest mapping(BytesReference source, MediaType mediaType) { * @param source The mapping source */ public CreateIndexRequest mapping(XContentBuilder source) { - return mapping(BytesReference.bytes(source), source.contentType()); + return mapping(BytesReferenceUtil.bytes(source), source.contentType()); } /** @@ -376,7 +377,7 @@ public CreateIndexRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReference.bytes(builder)); + return aliases(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -386,7 +387,7 @@ public CreateIndexRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public CreateIndexRequest aliases(XContentBuilder source) { - return aliases(BytesReference.bytes(source)); + return aliases(BytesReferenceUtil.bytes(source)); } /** @@ -444,7 +445,7 @@ public CreateIndexRequest source(String source, MediaType mediaType) { * Sets the settings and mappings as a single source. */ public CreateIndexRequest source(XContentBuilder source) { - return source(BytesReference.bytes(source), source.contentType()); + return source(BytesReferenceUtil.bytes(source), source.contentType()); } /** diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java index a9e5e8f1484b8..4a75b96354c69 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java @@ -34,6 +34,7 @@ import org.opensearch.Version; import org.opensearch.action.ActionResponse; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -195,7 +196,7 @@ public static class FieldMappingMetadata implements ToXContentFragment { PARSER.declareField(optionalConstructorArg(), (p, c) -> p.text(), FULL_NAME, ObjectParser.ValueType.STRING); PARSER.declareField(optionalConstructorArg(), (p, c) -> { final XContentBuilder jsonBuilder = jsonBuilder().copyCurrentStructure(p); - final BytesReference bytes = BytesReference.bytes(jsonBuilder); + final BytesReference bytes = BytesReferenceUtil.bytes(jsonBuilder); return bytes; }, MAPPING, ObjectParser.ValueType.OBJECT); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java index 200c12fd90a72..b0cae3585410b 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -44,6 +44,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -290,7 +291,7 @@ public static XContentBuilder simpleMapping(String... source) { * The mapping source definition. */ public PutMappingRequest source(XContentBuilder mappingBuilder) { - return source(BytesReference.bytes(mappingBuilder), mappingBuilder.contentType()); + return source(BytesReferenceUtil.bytes(mappingBuilder), mappingBuilder.contentType()); } /** @@ -300,7 +301,7 @@ public PutMappingRequest source(Map mappingSource) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(mappingSource); - return source(BytesReference.bytes(builder), builder.contentType()); + return source(BytesReferenceUtil.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + mappingSource + "]", e); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index 0ab896bf87750..e0cb579004071 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -48,6 +48,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -271,7 +272,7 @@ public PutIndexTemplateRequest mapping(String source, MediaType mediaType) { * @param source The mapping source */ public PutIndexTemplateRequest mapping(XContentBuilder source) { - return mapping(BytesReference.bytes(source), source.contentType()); + return mapping(BytesReferenceUtil.bytes(source), source.contentType()); } /** @@ -323,7 +324,7 @@ public String mappings() { */ public PutIndexTemplateRequest source(XContentBuilder templateBuilder) { try { - return source(BytesReference.bytes(templateBuilder), templateBuilder.contentType()); + return source(BytesReferenceUtil.bytes(templateBuilder), templateBuilder.contentType()); } catch (Exception e) { throw new IllegalArgumentException("Failed to build json for template request", e); } @@ -427,7 +428,7 @@ public PutIndexTemplateRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReference.bytes(builder)); + return aliases(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -437,7 +438,7 @@ public PutIndexTemplateRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public PutIndexTemplateRequest aliases(XContentBuilder source) { - return aliases(BytesReference.bytes(source)); + return aliases(BytesReferenceUtil.bytes(source)); } /** diff --git a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java index e0bc2ae5d0e18..705561e7c90e4 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java @@ -33,7 +33,7 @@ package org.opensearch.action.bulk; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.ExceptionsHelper; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.DocWriteRequest.OpType; @@ -144,7 +144,7 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw } RestStatus status = null; - OpenSearchException exception = null; + BaseOpenSearchException exception = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); @@ -152,7 +152,7 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw if (ERROR.equals(currentFieldName)) { if (token == XContentParser.Token.START_OBJECT) { - exception = OpenSearchException.fromXContent(parser); + exception = BaseOpenSearchException.fromXContent(parser); } } else if (STATUS.equals(currentFieldName)) { if (token == XContentParser.Token.VALUE_NUMBER) { @@ -219,7 +219,7 @@ public Failure(String index, String id, Exception cause) { index, id, cause, - ExceptionsHelper.status(cause), + BaseExceptionsHelper.status(cause), SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, false @@ -231,7 +231,7 @@ public Failure(String index, String id, Exception cause, boolean aborted) { index, id, cause, - ExceptionsHelper.status(cause), + BaseExceptionsHelper.status(cause), SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, aborted @@ -244,7 +244,7 @@ public Failure(String index, String id, Exception cause, RestStatus status) { /** For write failures after operation was assigned a sequence number. */ public Failure(String index, String id, Exception cause, long seqNo, long term) { - this(index, id, cause, ExceptionsHelper.status(cause), seqNo, term, false); + this(index, id, cause, BaseExceptionsHelper.status(cause), seqNo, term, false); } private Failure(String index, String id, Exception cause, RestStatus status, long seqNo, long term, boolean aborted) { @@ -269,7 +269,7 @@ public Failure(StreamInput in) throws IOException { } id = in.readOptionalString(); cause = in.readException(); - status = ExceptionsHelper.status(cause); + status = BaseExceptionsHelper.status(cause); seqNo = in.readZLong(); term = in.readVLong(); aborted = in.readBoolean(); diff --git a/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java b/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java index 3e2aa1316a7cc..439a6694bde7f 100644 --- a/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java +++ b/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java @@ -33,7 +33,6 @@ package org.opensearch.action.get; import org.opensearch.BaseOpenSearchException; -import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.ActionResponse; import org.opensearch.common.io.stream.StreamInput; @@ -209,7 +208,7 @@ private static MultiGetItemResponse parseItem(XContentParser parser) throws IOEx String currentFieldName = null; String index = null; String id = null; - OpenSearchException exception = null; + BaseOpenSearchException exception = null; GetResult getResult = null; for (Token token = parser.nextToken(); token != Token.END_OBJECT; token = parser.nextToken()) { switch (token) { @@ -231,7 +230,7 @@ private static MultiGetItemResponse parseItem(XContentParser parser) throws IOEx break; case START_OBJECT: if (ERROR.match(currentFieldName, parser.getDeprecationHandler())) { - exception = OpenSearchException.fromXContent(parser); + exception = BaseOpenSearchException.fromXContent(parser); } break; default: diff --git a/server/src/main/java/org/opensearch/action/index/IndexRequest.java b/server/src/main/java/org/opensearch/action/index/IndexRequest.java index 1cce14ef447f5..ffe9998033084 100644 --- a/server/src/main/java/org/opensearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/opensearch/action/index/IndexRequest.java @@ -54,6 +54,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.unit.ByteSizeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -396,7 +397,7 @@ public IndexRequest source(String source, XContentType xContentType) { * Sets the content source to index. */ public IndexRequest source(XContentBuilder sourceBuilder) { - return source(BytesReference.bytes(sourceBuilder), sourceBuilder.contentType()); + return source(BytesReferenceUtil.bytes(sourceBuilder), sourceBuilder.contentType()); } /** diff --git a/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java b/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java index 6890252cec014..c79aa6bb6f64b 100644 --- a/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java +++ b/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java @@ -34,9 +34,9 @@ import org.opensearch.action.ActionResponse; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.StatusToXContentObject; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -128,7 +128,7 @@ public static GetPipelineResponse fromXContent(XContentParser parser) throws IOE contentBuilder.generator().copyCurrentStructure(parser); PipelineConfiguration pipeline = new PipelineConfiguration( pipelineId, - BytesReference.bytes(contentBuilder), + BytesReferenceUtil.bytes(contentBuilder), contentBuilder.contentType() ); pipelines.add(pipeline); diff --git a/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java b/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java index 0fdd340c420b3..26222d0d9730e 100644 --- a/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java +++ b/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java @@ -63,7 +63,7 @@ public final class SimulateDocumentBaseResult implements SimulateDocumentResult return new SimulateDocumentBaseResult(((WriteableIngestDocument) a[0]).getIngestDocument()); } else { assert a[0] == null; - return new SimulateDocumentBaseResult((OpenSearchException) a[1]); + return new SimulateDocumentBaseResult((BaseOpenSearchException) a[1]); } } ); diff --git a/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java b/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java index badddd5152bc9..a089f40990b7f 100644 --- a/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java +++ b/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java @@ -88,10 +88,10 @@ public static Status fromString(String string) { private final Exception failure; private final Tuple conditionalWithResult; - private static final ConstructingObjectParser IGNORED_ERROR_PARSER = new ConstructingObjectParser<>( + private static final ConstructingObjectParser IGNORED_ERROR_PARSER = new ConstructingObjectParser<>( "ignored_error_parser", true, - a -> (OpenSearchException) a[0] + a -> (BaseOpenSearchException) a[0] ); static { IGNORED_ERROR_PARSER.declareObject(constructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField("error")); @@ -123,9 +123,9 @@ public static Status fromString(String string) { IngestDocument document = a[4] == null ? null : ((WriteableIngestDocument) a[4]).getIngestDocument(); Exception failure = null; if (a[5] != null) { - failure = (OpenSearchException) a[5]; + failure = (BaseOpenSearchException) a[5]; } else if (a[6] != null) { - failure = (OpenSearchException) a[6]; + failure = (BaseOpenSearchException) a[6]; } return new SimulateProcessorResult(type, processorTag, description, document, failure, conditionalWithResult); diff --git a/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java b/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java index 4fd86febcb0ae..00587ad180af0 100644 --- a/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java +++ b/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java @@ -10,9 +10,9 @@ import org.opensearch.action.ActionResponse; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.StatusToXContentObject; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -82,7 +82,7 @@ public static GetSearchPipelineResponse fromXContent(XContentParser parser) thro contentBuilder.generator().copyCurrentStructure(parser); PipelineConfiguration pipeline = new PipelineConfiguration( pipelineId, - BytesReference.bytes(contentBuilder), + BytesReferenceUtil.bytes(contentBuilder), contentBuilder.contentType() ); pipelines.add(pipeline); diff --git a/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java b/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java index d1095840189aa..634338e418b50 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java @@ -42,6 +42,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.logging.DeprecationLogger; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -328,7 +329,7 @@ public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, for (SearchRequest request : multiSearchRequest.requests()) { try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { writeSearchRequestParams(request, xContentBuilder); - BytesReference.bytes(xContentBuilder).writeTo(output); + BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { @@ -338,7 +339,7 @@ public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, xContentBuilder.startObject(); xContentBuilder.endObject(); } - BytesReference.bytes(xContentBuilder).writeTo(output); + BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); } diff --git a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java index d3c4dcab79d7f..43efa575b9110 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java @@ -32,9 +32,9 @@ package org.opensearch.action.search; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; -import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionResponse; import org.opensearch.common.Nullable; import org.opensearch.common.Strings; @@ -193,7 +193,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); if (item.isFailure()) { BaseOpenSearchException.generateFailureXContent(builder, params, item.getFailure(), true); - builder.field(Fields.STATUS, ExceptionsHelper.status(item.getFailure()).getStatus()); + builder.field(Fields.STATUS, BaseExceptionsHelper.status(item.getFailure()).getStatus()); } else { item.getResponse().innerToXContent(builder, params); builder.field(Fields.STATUS, item.getResponse().status().getStatus()); diff --git a/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java b/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java index 891d9a1e2e924..82429a1c2254f 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java +++ b/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java @@ -101,7 +101,7 @@ public RestStatus status() { if (shardFailures.length == 0) { // if no successful shards, the failure can be due to OpenSearchRejectedExecutionException during fetch phase // on coordinator node. so get the status from cause instead of returning SERVICE_UNAVAILABLE blindly - return getCause() == null ? RestStatus.SERVICE_UNAVAILABLE : ExceptionsHelper.status(getCause()); + return getCause() == null ? RestStatus.SERVICE_UNAVAILABLE : BaseExceptionsHelper.status(getCause()); } RestStatus status = shardFailures[0].status(); if (shardFailures.length > 1) { diff --git a/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java b/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java index c820b7ada427a..80465a75da764 100644 --- a/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java +++ b/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java @@ -33,8 +33,7 @@ package org.opensearch.action.search; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.ExceptionsHelper; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.cluster.metadata.IndexMetadata; @@ -94,7 +93,7 @@ private ShardSearchFailure(final Exception e, final Throwable unwrappedCause, @N shardTarget == null ? null : shardTarget.getFullyQualifiedIndexName(), shardTarget == null ? -1 : shardTarget.getShardId().getId(), BaseExceptionsHelper.detailedMessage(e), - ExceptionsHelper.status(unwrappedCause), + BaseExceptionsHelper.status(unwrappedCause), unwrappedCause ); @@ -163,7 +162,7 @@ public static ShardSearchFailure fromXContent(XContentParser parser) throws IOEx String indexName = null; String clusterAlias = null; String nodeId = null; - OpenSearchException exception = null; + BaseOpenSearchException exception = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); @@ -184,7 +183,7 @@ public static ShardSearchFailure fromXContent(XContentParser parser) throws IOEx } } else if (token == XContentParser.Token.START_OBJECT) { if (REASON_FIELD.equals(currentFieldName)) { - exception = OpenSearchException.fromXContent(parser); + exception = BaseOpenSearchException.fromXContent(parser); } else { parser.skipChildren(); } diff --git a/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java b/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java index 3cec823422eb2..968feca583d07 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java +++ b/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java @@ -36,7 +36,6 @@ import org.apache.lucene.store.AlreadyClosedException; import org.opensearch.BaseExceptionsHelper; import org.opensearch.core.Assertions; -import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.UnavailableShardsException; @@ -285,7 +284,7 @@ public void onFailure(Exception replicaException) { // Only report "critical" exceptions // TODO: Reach out to the cluster-manager node to get the latest shard state then report. if (TransportActions.isShardNotAvailableException(replicaException) == false) { - RestStatus restStatus = ExceptionsHelper.status(replicaException); + RestStatus restStatus = BaseExceptionsHelper.status(replicaException); shardReplicaFailures.add( new ReplicationResponse.ShardInfo.Failure( shard.shardId(), diff --git a/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java b/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java index 1b3b72d45b5b5..a2be1bd7cd12a 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java +++ b/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java @@ -33,7 +33,7 @@ package org.opensearch.action.support.replication; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.cluster.metadata.IndexMetadata; @@ -320,7 +320,7 @@ public static Failure fromXContent(XContentParser parser) throws IOException { int shardId = -1; boolean primary = false; RestStatus status = null; - OpenSearchException reason = null; + BaseOpenSearchException reason = null; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -340,7 +340,7 @@ public static Failure fromXContent(XContentParser parser) throws IOException { } } else if (token == XContentParser.Token.START_OBJECT) { if (REASON.equals(currentFieldName)) { - reason = OpenSearchException.fromXContent(parser); + reason = BaseOpenSearchException.fromXContent(parser); } else { parser.skipChildren(); // skip potential inner objects for forward compatibility } diff --git a/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java b/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java index b4bacefad8ad2..e85b77eba0416 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java +++ b/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java @@ -33,7 +33,7 @@ package org.opensearch.action.support.replication; import com.carrotsearch.hppc.cursors.IntObjectCursor; -import org.opensearch.ExceptionsHelper; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.DefaultShardOperationFailedException; @@ -122,7 +122,7 @@ public void onFailure(Exception e) { shardId, null, e, - ExceptionsHelper.status(e), + BaseExceptionsHelper.status(e), true ); failures = new ReplicationResponse.ShardInfo.Failure[totalNumCopies]; diff --git a/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java b/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java index fd90f9b389819..8621598aea0f1 100644 --- a/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java +++ b/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java @@ -32,6 +32,7 @@ package org.opensearch.action.support.tasks; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.FailedNodeException; @@ -62,7 +63,7 @@ public class BaseTasksResponse extends ActionResponse { protected static final String NODE_FAILURES = "node_failures"; private List taskFailures; - private List nodeFailures; + private List nodeFailures; public BaseTasksResponse(List taskFailures, List nodeFailures) { this.taskFailures = taskFailures == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(taskFailures)); @@ -92,7 +93,7 @@ public void writeTo(StreamOutput out) throws IOException { exp.writeTo(out); } out.writeVInt(nodeFailures.size()); - for (OpenSearchException exp : nodeFailures) { + for (BaseOpenSearchException exp : nodeFailures) { exp.writeTo(out); } } @@ -107,7 +108,7 @@ public List getTaskFailures() { /** * The list of node failures exception. */ - public List getNodeFailures() { + public List getNodeFailures() { return nodeFailures; } @@ -144,7 +145,7 @@ protected void toXContentCommon(XContentBuilder builder, ToXContent.Params param if (getNodeFailures() != null && getNodeFailures().size() > 0) { builder.startArray(NODE_FAILURES); - for (OpenSearchException ex : getNodeFailures()) { + for (BaseOpenSearchException ex : getNodeFailures()) { builder.startObject(); ex.toXContent(builder, params); builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java b/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java index 2a170dec776a4..911061d8737fb 100644 --- a/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java +++ b/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java @@ -40,6 +40,7 @@ import org.opensearch.action.get.MultiGetRequest; import org.opensearch.action.support.single.shard.SingleShardRequest; import org.opensearch.common.Nullable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; @@ -293,7 +294,7 @@ public XContentType xContentType() { * Sets an artificial document from which term vectors are requested for. */ public TermVectorsRequest doc(XContentBuilder documentBuilder) { - return this.doc(BytesReference.bytes(documentBuilder), true, documentBuilder.contentType()); + return this.doc(BytesReferenceUtil.bytes(documentBuilder), true, documentBuilder.contentType()); } /** diff --git a/server/src/main/java/org/opensearch/action/update/UpdateHelper.java b/server/src/main/java/org/opensearch/action/update/UpdateHelper.java index 47a764f9effa3..ef217f3c5e9b0 100644 --- a/server/src/main/java/org/opensearch/action/update/UpdateHelper.java +++ b/server/src/main/java/org/opensearch/action/update/UpdateHelper.java @@ -44,6 +44,7 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -369,7 +370,7 @@ public static GetResult extractGetResult( BytesStreamOutput streamOutput = new BytesStreamOutput(initialCapacity); try (XContentBuilder builder = new XContentBuilder(sourceContentType.xContent(), streamOutput)) { builder.value(value); - sourceFilteredAsBytes = BytesReference.bytes(builder); + sourceFilteredAsBytes = BytesReferenceUtil.bytes(builder); } } catch (IOException e) { throw new OpenSearchException("Error filtering source", e); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java index 72b6380e78a1e..1d4bf25babef7 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java @@ -36,10 +36,10 @@ import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; import org.opensearch.common.Nullable; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -317,7 +317,7 @@ public Builder filter(Map filter) { } try { XContentBuilder builder = XContentFactory.jsonBuilder().map(filter); - this.filter = new CompressedXContent(BytesReference.bytes(builder)); + this.filter = new CompressedXContent(BytesReferenceUtil.bytes(builder)); return this; } catch (IOException e) { throw new OpenSearchGenerationException("Failed to build json for alias request", e); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java index 23d2a1667afaf..5b63ab3e27d73 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java @@ -35,10 +35,10 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -89,7 +89,7 @@ public MappingMetadata(String type, Map mapping) { this.type = type; try { XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping); - this.source = new CompressedXContent(BytesReference.bytes(mappingBuilder)); + this.source = new CompressedXContent(BytesReferenceUtil.bytes(mappingBuilder)); } catch (IOException e) { throw new UncheckedIOException(e); // XContent exception, should never happen } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java index 76860e568f1a1..8fefab67fa50a 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java @@ -50,7 +50,6 @@ import org.opensearch.common.Priority; import org.opensearch.common.UUIDs; import org.opensearch.common.ValidationException; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.inject.Inject; import org.opensearch.common.logging.HeaderWarning; @@ -58,6 +57,7 @@ import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -1153,7 +1153,7 @@ public static List collectMappings(final ClusterState state, .map(mapping -> { try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { builder.value(mapping); - return new CompressedXContent(BytesReference.bytes(builder)); + return new CompressedXContent(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/server/src/main/java/org/opensearch/common/Strings.java b/server/src/main/java/org/opensearch/common/Strings.java index 0bec840a15f40..cd9e2d1734232 100644 --- a/server/src/main/java/org/opensearch/common/Strings.java +++ b/server/src/main/java/org/opensearch/common/Strings.java @@ -36,6 +36,7 @@ import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; @@ -245,7 +246,7 @@ public static String toString(MediaType mediaType, ToXContent toXContent, ToXCon * @param xContentBuilder builder containing an object to converted to a string */ public static String toString(XContentBuilder xContentBuilder) { - return BytesReference.bytes(xContentBuilder).utf8ToString(); + return BytesReferenceUtil.bytes(xContentBuilder).utf8ToString(); } /** diff --git a/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java index 707b32a0c50f3..22c83804f1518 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java @@ -147,7 +147,7 @@ public int available() throws IOException { } @Override - protected void ensureCanReadBytes(int length) throws EOFException { + public void ensureCanReadBytes(int length) throws EOFException { if (buffer.remaining() < length) { throw new EOFException("tried to read: " + length + " bytes but only " + buffer.remaining() + " remaining"); } diff --git a/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java index 8bf1fe846cd8b..fe87102f85cfc 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java @@ -106,7 +106,7 @@ public int available() { } @Override - protected void ensureCanReadBytes(int length) throws EOFException { + public void ensureCanReadBytes(int length) throws EOFException { int available = available(); if (length > available) { throw new EOFException("attempting to read " + length + " bytes but only " + available + " bytes are available"); diff --git a/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java index 5f6bbd7c16cf3..82776eae51401 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java @@ -106,7 +106,7 @@ public void setVersion(Version version) { } @Override - protected void ensureCanReadBytes(int length) throws EOFException { + public void ensureCanReadBytes(int length) throws EOFException { delegate.ensureCanReadBytes(length); } diff --git a/server/src/main/java/org/opensearch/common/io/stream/Streamables.java b/server/src/main/java/org/opensearch/common/io/stream/Streamables.java index abaaa020cfd5b..e594247be708e 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/Streamables.java +++ b/server/src/main/java/org/opensearch/common/io/stream/Streamables.java @@ -12,8 +12,7 @@ import org.joda.time.ReadableInstant; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.time.DateUtils; -import org.opensearch.core.common.io.stream.BaseWriteable.WriteableRegistry; -import org.opensearch.core.common.io.stream.BaseWriteable; +import org.opensearch.common.io.stream.Writeable.WriteableRegistry; import org.opensearch.script.JodaCompatibleZonedDateTime; import java.time.Instant; @@ -47,7 +46,7 @@ public static void registerStreamables() { */ private static void registerWriters() { /** {@link ReadableInstant} */ - WriteableRegistry.>registerWriter(ReadableInstant.class, (o, v) -> { + WriteableRegistry.registerWriter(ReadableInstant.class, (o, v) -> { o.writeByte((byte) 13); final ReadableInstant instant = (ReadableInstant) v; o.writeString(instant.getZone().getID()); @@ -55,7 +54,7 @@ private static void registerWriters() { }); WriteableRegistry.registerClassAlias(ReadableInstant.class, ReadableInstant.class); /** {@link JodaCompatibleZonedDateTime} */ - WriteableRegistry.>registerWriter(JodaCompatibleZonedDateTime.class, (o, v) -> { + WriteableRegistry.registerWriter(JodaCompatibleZonedDateTime.class, (o, v) -> { // write the joda compatibility datetime as joda datetime o.writeByte((byte) 13); final JodaCompatibleZonedDateTime zonedDateTime = (JodaCompatibleZonedDateTime) v; @@ -65,7 +64,7 @@ private static void registerWriters() { o.writeLong(zonedDateTime.toInstant().toEpochMilli()); }); /** {@link GeoPoint} */ - BaseWriteable.WriteableRegistry.>registerWriter(GeoPoint.class, (o, v) -> { + WriteableRegistry.registerWriter(GeoPoint.class, (o, v) -> { o.writeByte((byte) 22); ((GeoPoint) v).writeTo(o); }); @@ -78,12 +77,12 @@ private static void registerWriters() { */ private static void registerReaders() { /** {@link JodaCompatibleZonedDateTime */ - WriteableRegistry.>registerReader(Byte.valueOf((byte) 13), (i) -> { + WriteableRegistry.registerReader(Byte.valueOf((byte) 13), (i) -> { final ZoneId zoneId = DateUtils.dateTimeZoneToZoneId(DateTimeZone.forID(i.readString())); long millis = i.readLong(); return new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), zoneId); }); /** {@link GeoPoint} */ - WriteableRegistry.>registerReader(Byte.valueOf((byte) 22), GeoPoint::new); + WriteableRegistry.registerReader(Byte.valueOf((byte) 22), GeoPoint::new); } } diff --git a/server/src/main/java/org/opensearch/common/io/stream/Writeable.java b/server/src/main/java/org/opensearch/common/io/stream/Writeable.java deleted file mode 100644 index c04cd7977fdc0..0000000000000 --- a/server/src/main/java/org/opensearch/common/io/stream/Writeable.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.common.io.stream; - -import org.opensearch.core.common.io.stream.BaseWriteable; - -import java.io.IOException; - -/** - * Implementers can be written to a {@linkplain StreamOutput} and read from a {@linkplain StreamInput}. This allows them to be "thrown - * across the wire" using OpenSearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by - * serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged. - * - * @opensearch.internal - */ -public interface Writeable extends BaseWriteable { - - /** - * Write this into the {@linkplain StreamOutput}. - */ - void writeTo(StreamOutput out) throws IOException; - - /** - * Reference to a method that can write some object to a {@link StreamOutput}. - *

- * By convention this is a method from {@link StreamOutput} itself (e.g., {@link StreamOutput#writeString}). If the value can be - * {@code null}, then the "optional" variant of methods should be used! - *

- * Most classes should implement {@link Writeable} and the {@link Writeable#writeTo(StreamOutput)} method should use - * {@link StreamOutput} methods directly or this indirectly: - *


-     * public void writeTo(StreamOutput out) throws IOException {
-     *     out.writeVInt(someValue);
-     *     out.writeMapOfLists(someMap, StreamOutput::writeString, StreamOutput::writeString);
-     * }
-     * 
- */ - @FunctionalInterface - interface Writer extends BaseWriteable.Writer {} - - /** - * Reference to a method that can read some object from a stream. By convention this is a constructor that takes - * {@linkplain StreamInput} as an argument for most classes and a static method for things like enums. Returning null from one of these - * is always wrong - for that we use methods like {@link StreamInput#readOptionalWriteable(Reader)}. - *

- * As most classes will implement this via a constructor (or a static method in the case of enumerations), it's something that should - * look like: - *


-     * public MyClass(final StreamInput in) throws IOException {
-     *     this.someValue = in.readVInt();
-     *     this.someMap = in.readMapOfLists(StreamInput::readString, StreamInput::readString);
-     * }
-     * 
- */ - @FunctionalInterface - interface Reader extends BaseWriteable.Reader {} - -} diff --git a/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java b/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java new file mode 100644 index 0000000000000..cd5fd9ede8942 --- /dev/null +++ b/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.common.util; + +import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.io.stream.BytesStream; +import org.opensearch.core.xcontent.XContentBuilder; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; + +public class BytesReferenceUtil { + /** + * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder, + * so no further fields may be added. + */ + public static BytesReference bytes(XContentBuilder xContentBuilder) { + xContentBuilder.close(); + OutputStream stream = xContentBuilder.getOutputStream(); + if (stream instanceof ByteArrayOutputStream) { + return new BytesArray(((ByteArrayOutputStream) stream).toByteArray()); + } else { + return ((BytesStream) stream).bytes(); + } + } +} diff --git a/server/src/main/java/org/opensearch/common/util/PageCacheRecycler.java b/server/src/main/java/org/opensearch/common/util/PageCacheRecycler.java index 6d786e85bab1c..429dce6a69e75 100644 --- a/server/src/main/java/org/opensearch/common/util/PageCacheRecycler.java +++ b/server/src/main/java/org/opensearch/common/util/PageCacheRecycler.java @@ -33,6 +33,7 @@ package org.opensearch.common.util; import org.apache.lucene.util.RamUsageEstimator; +import org.opensearch.common.bytes.PagedBytesReference; import org.opensearch.common.recycler.AbstractRecyclerC; import org.opensearch.common.recycler.Recycler; import org.opensearch.common.settings.Setting; @@ -94,7 +95,7 @@ public class PageCacheRecycler { ); /** Page size in bytes: 16KB */ - public static final int PAGE_SIZE_IN_BYTES = 1 << 14; + public static final int PAGE_SIZE_IN_BYTES = PagedBytesReference.PAGE_SIZE_IN_BYTES; public static final int OBJECT_PAGE_SIZE = PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_OBJECT_REF; public static final int LONG_PAGE_SIZE = PAGE_SIZE_IN_BYTES / Long.BYTES; public static final int INT_PAGE_SIZE = PAGE_SIZE_IN_BYTES / Integer.BYTES; diff --git a/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java b/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java index 0859738478fc2..12484c378b5f0 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java +++ b/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java @@ -8,7 +8,7 @@ package org.opensearch.common.xcontent; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.AbstractXContentParser; import org.opensearch.core.xcontent.DeprecationHandler; @@ -70,7 +70,7 @@ public XContentParser parseObject() throws IOException { builder.field(this.fieldTypeName + VALUE_SUFFIX, valueList); builder.field(this.fieldTypeName + VALUE_AND_PATH_SUFFIX, valueAndPathList); builder.endObject(); - String jString = XContentHelper.convertToJson(BytesReference.bytes(builder), false, XContentType.JSON); + String jString = XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder), false, XContentType.JSON); return JsonXContent.jsonXContent.createParser(this.xContentRegistry, this.deprecationHandler, String.valueOf(jString)); } diff --git a/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java b/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java index be98d1cf73515..08fb014513d59 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java +++ b/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java @@ -33,6 +33,7 @@ package org.opensearch.common.xcontent; import org.opensearch.common.CheckedFunction; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.AbstractObjectParser; @@ -64,7 +65,7 @@ public void declareRawObject( final CheckedFunction bytesParser = p -> { try (XContentBuilder builder = JsonXContent.contentBuilder()) { builder.copyCurrentStructure(p); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } }; parser.declareField(consumer, bytesParser, field, ValueType.OBJECT); diff --git a/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java b/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java index 482549ae194bd..b7c87a6d653ef 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java +++ b/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java @@ -39,6 +39,7 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.compress.Compressor; import org.opensearch.common.compress.CompressorFactory; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -520,7 +521,7 @@ public static BytesReference toXContent(ToXContent toXContent, XContentType xCon if (toXContent.isFragment()) { builder.endObject(); } - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } @@ -540,7 +541,7 @@ public static BytesReference toXContent(ToXContent toXContent, MediaType mediaTy if (toXContent.isFragment()) { builder.endObject(); } - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } @@ -585,6 +586,6 @@ public static BytesReference childBytes(XContentParser parser) throws IOExceptio } XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent()); builder.copyCurrentStructure(parser); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } diff --git a/server/src/main/java/org/opensearch/index/get/GetResult.java b/server/src/main/java/org/opensearch/index/get/GetResult.java index a88294943c087..5a18032b52686 100644 --- a/server/src/main/java/org/opensearch/index/get/GetResult.java +++ b/server/src/main/java/org/opensearch/index/get/GetResult.java @@ -41,6 +41,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -378,7 +379,7 @@ public static GetResult fromXContentEmbedded(XContentParser parser, String index // the original document gets slightly modified: whitespaces or pretty printing are not preserved, // it all depends on the current builder settings builder.copyCurrentStructure(parser); - source = BytesReference.bytes(builder); + source = BytesReferenceUtil.bytes(builder); } } else if (FIELDS.equals(currentFieldName)) { while (parser.nextToken() != XContentParser.Token.END_OBJECT) { diff --git a/server/src/main/java/org/opensearch/index/get/ShardGetService.java b/server/src/main/java/org/opensearch/index/get/ShardGetService.java index 08e2b32bded0e..034722259aa76 100644 --- a/server/src/main/java/org/opensearch/index/get/ShardGetService.java +++ b/server/src/main/java/org/opensearch/index/get/ShardGetService.java @@ -50,6 +50,7 @@ import org.opensearch.common.lucene.uid.VersionsAndSeqNoResolver.DocIdAndVersion; import org.opensearch.common.metrics.CounterMetric; import org.opensearch.common.metrics.MeanMetric; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -378,7 +379,7 @@ private GetResult innerGetLoadFromStoredFields( sourceAsMap = typeMapTuple.v2(); sourceAsMap = XContentMapValues.filter(sourceAsMap, fetchSourceContext.includes(), fetchSourceContext.excludes()); try { - source = BytesReference.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); + source = BytesReferenceUtil.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); } catch (IOException e) { throw new OpenSearchException("Failed to get id [" + id + "] with includes/excludes set", e); } @@ -406,7 +407,7 @@ private GetResult innerGetLoadFromStoredFields( sourceAsMap = typeMapTuple.v2(); sourceAsMap = XContentMapValues.filter(sourceAsMap, fetchSourceContext.includes(), fetchSourceContext.excludes()); try { - source = BytesReference.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); + source = BytesReferenceUtil.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); } catch (IOException e) { throw new OpenSearchException("Failed to get id [" + id + "] with includes/excludes set", e); } diff --git a/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java index 0804ad1a524a9..fd1df4e1e6666 100644 --- a/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java @@ -51,6 +51,7 @@ import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.BytesRef; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchParseException; import org.opensearch.common.Nullable; import org.opensearch.common.geo.ShapeRelation; @@ -116,7 +117,7 @@ public MappedFieldType( * @param searchLookup a {@link SearchLookup} supplier to allow for accessing other fields values in the context of runtime fields * @throws IllegalArgumentException if the fielddata is not supported on this type. * An IllegalArgumentException is needed in order to return an http error 400 - * when this error occurs in a request. see: {@link org.opensearch.ExceptionsHelper#status} + * when this error occurs in a request. see: {@link BaseExceptionsHelper#status} */ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier searchLookup) { throw new IllegalArgumentException("Fielddata is not supported on field [" + name() + "] of type [" + typeName() + "]"); @@ -411,7 +412,7 @@ public Relation isFieldWithinQuery( /** @throws IllegalArgumentException if the fielddata is not supported on this type. * An IllegalArgumentException is needed in order to return an http error 400 - * when this error occurs in a request. see: {@link org.opensearch.ExceptionsHelper#status} + * when this error occurs in a request. see: {@link BaseExceptionsHelper#status} **/ protected final void failIfNoDocValues() { if (hasDocValues() == false) { diff --git a/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java index cc5cae168e7b6..26831378b172e 100644 --- a/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java @@ -49,6 +49,7 @@ import org.opensearch.action.termvectors.TermVectorsResponse; import org.opensearch.client.Client; import org.opensearch.common.Nullable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.Strings; @@ -220,7 +221,7 @@ public Item(@Nullable String index, XContentBuilder doc) { throw new IllegalArgumentException("Item requires doc to be non-null"); } this.index = index; - this.doc = BytesReference.bytes(doc); + this.doc = BytesReferenceUtil.bytes(doc); this.xContentType = XContentType.fromMediaType(doc.contentType()); } @@ -373,7 +374,7 @@ public static Item parse(XContentParser parser, Item item) throws IOException { } else if (ID.match(currentFieldName, parser.getDeprecationHandler())) { item.id = parser.text(); } else if (DOC.match(currentFieldName, parser.getDeprecationHandler())) { - item.doc = BytesReference.bytes(jsonBuilder().copyCurrentStructure(parser)); + item.doc = BytesReferenceUtil.bytes(jsonBuilder().copyCurrentStructure(parser)); item.xContentType = XContentType.JSON; } else if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) { if (token == XContentParser.Token.START_ARRAY) { diff --git a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java index cab2d69ff0f9f..bcb3d6f4b2cc7 100644 --- a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java @@ -48,6 +48,7 @@ import org.opensearch.common.lucene.search.function.ScoreFunction; import org.opensearch.common.unit.DistanceUnit; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -146,7 +147,7 @@ protected DecayFunctionBuilder( } builder.field(DECAY, decay); builder.endObject(); - this.functionBytes = BytesReference.bytes(builder); + this.functionBytes = BytesReferenceUtil.bytes(builder); } catch (IOException e) { throw new IllegalArgumentException("unable to build inner function object", e); } diff --git a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java index ea27625844337..af39bea62019e 100644 --- a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java +++ b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java @@ -32,6 +32,7 @@ package org.opensearch.index.query.functionscore; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesReference; @@ -124,7 +125,7 @@ public DFB fromXContent(XContentParser parser) throws IOException, ParsingExcept fieldName = currentFieldName; XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); - functionBytes = BytesReference.bytes(builder); + functionBytes = BytesReferenceUtil.bytes(builder); } else if (MULTI_VALUE_MODE.match(currentFieldName, parser.getDeprecationHandler())) { multiValueMode = MultiValueMode.fromString(parser.text()); } else { diff --git a/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java b/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java index 9060487f6364f..b2919bf23543f 100644 --- a/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java +++ b/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java @@ -32,7 +32,7 @@ package org.opensearch.index.reindex; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchParseException; import org.opensearch.action.ActionResponse; import org.opensearch.action.bulk.BulkItemResponse.Failure; @@ -246,8 +246,8 @@ private static Object parseFailure(XContentParser parser) throws IOException { Integer status = null; Integer shardId = null; String nodeId = null; - OpenSearchException bulkExc = null; - OpenSearchException searchExc = null; + BaseOpenSearchException bulkExc = null; + BaseOpenSearchException searchExc = null; while ((token = parser.nextToken()) != Token.END_OBJECT) { ensureExpectedToken(Token.FIELD_NAME, token, parser); String name = parser.currentName(); @@ -257,10 +257,10 @@ private static Object parseFailure(XContentParser parser) throws IOException { } else if (token == Token.START_OBJECT) { switch (name) { case SearchFailure.REASON_FIELD: - searchExc = OpenSearchException.fromXContent(parser); + searchExc = BaseOpenSearchException.fromXContent(parser); break; case Failure.CAUSE_FIELD: - bulkExc = OpenSearchException.fromXContent(parser); + bulkExc = BaseOpenSearchException.fromXContent(parser); break; default: parser.skipChildren(); diff --git a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java index ffd4bfb86afa5..e8b56dbbdd678 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java +++ b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java @@ -36,8 +36,8 @@ import org.opensearch.action.CompositeIndicesRequest; import org.opensearch.action.index.IndexRequest; import org.opensearch.action.search.SearchRequest; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.logging.DeprecationLogger; @@ -359,7 +359,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType()); builder.map(source); try ( - InputStream stream = BytesReference.bytes(builder).streamInput(); + InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); XContentParser innerParser = parser.contentType() .xContent() .createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), stream) diff --git a/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java b/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java index d5d69d5a6d3f8..d67b5ec03c060 100644 --- a/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java +++ b/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -270,14 +271,14 @@ static BytesReference queryForRemote(Map source) throws IOExcept XContentBuilder builder = XContentBuilder.builder(QUERY_CONTENT_TYPE).prettyPrint(); Object query = source.remove("query"); if (query == null) { - return BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); + return BytesReferenceUtil.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); } if (!(query instanceof Map)) { throw new IllegalArgumentException("Expected [query] to be an object but was [" + query + "]"); } @SuppressWarnings("unchecked") Map map = (Map) query; - return BytesReference.bytes(builder.map(map)); + return BytesReferenceUtil.bytes(builder.map(map)); } private static boolean isQueryJson(BytesReference bytesReference) { diff --git a/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java b/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java index 8628bd84da35a..78a3835cf7b33 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java +++ b/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java @@ -34,7 +34,6 @@ import org.apache.logging.log4j.Logger; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.bulk.BackoffPolicy; import org.opensearch.action.bulk.BulkItemResponse; @@ -409,7 +408,7 @@ public static class SearchFailure implements Writeable, ToXContentObject { public static final String STATUS_FIELD = BulkItemResponse.Failure.STATUS_FIELD; public SearchFailure(Throwable reason, @Nullable String index, @Nullable Integer shardId, @Nullable String nodeId) { - this(reason, index, shardId, nodeId, ExceptionsHelper.status(reason)); + this(reason, index, shardId, nodeId, BaseExceptionsHelper.status(reason)); } public SearchFailure( @@ -441,7 +440,7 @@ public SearchFailure(StreamInput in) throws IOException { index = in.readOptionalString(); shardId = in.readOptionalVInt(); nodeId = in.readOptionalString(); - status = ExceptionsHelper.status(reason); + status = BaseExceptionsHelper.status(reason); } @Override diff --git a/server/src/main/java/org/opensearch/index/shard/IndexShard.java b/server/src/main/java/org/opensearch/index/shard/IndexShard.java index e368ee82b1084..ec6d8a7b73c99 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -57,6 +57,7 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ThreadInterruptedException; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.common.lucene.store.ByteArrayIndexInput; import org.opensearch.cluster.metadata.DataStream; import org.opensearch.core.Assertions; @@ -2212,7 +2213,7 @@ int runTranslogRecovery(Engine engine, Translog.Snapshot snapshot, Engine.Operat onOperationRecovered.run(); } catch (Exception e) { // TODO: Don't enable this leniency unless users explicitly opt-in - if (origin == Engine.Operation.Origin.LOCAL_TRANSLOG_RECOVERY && ExceptionsHelper.status(e) == RestStatus.BAD_REQUEST) { + if (origin == Engine.Operation.Origin.LOCAL_TRANSLOG_RECOVERY && BaseExceptionsHelper.status(e) == RestStatus.BAD_REQUEST) { // mainly for MapperParsingException and Failure to detect xcontent logger.info("ignoring recovery of a corrupt translog entry", e); } else { diff --git a/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java b/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java index dc41d1985fe42..622f1428953a5 100644 --- a/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java +++ b/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java @@ -37,7 +37,7 @@ import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchParseException; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -575,7 +575,7 @@ private static Script extractConditional(Map config) throws IOEx if (scriptSource != null) { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(normalizeScript(scriptSource)); - InputStream stream = BytesReference.bytes(builder).streamInput(); + InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java b/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java index 07d0c31fc6703..77048d500926c 100644 --- a/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java +++ b/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java @@ -34,6 +34,7 @@ import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; @@ -64,7 +65,7 @@ public final class PipelineConfiguration extends AbstractDiffable { XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent()); contentBuilder.generator().copyCurrentStructure(parser); - builder.setConfig(BytesReference.bytes(contentBuilder), contentBuilder.contentType()); + builder.setConfig(BytesReferenceUtil.bytes(contentBuilder), contentBuilder.contentType()); }, new ParseField("config"), ObjectParser.ValueType.OBJECT); } diff --git a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java index c0d6f49a5ce0d..40e23bc625433 100644 --- a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java @@ -92,6 +92,7 @@ import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.AbstractRunnable; import org.opensearch.common.util.concurrent.ConcurrentCollections; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -1667,7 +1668,7 @@ private void doGetRepositoryData(ActionListener listener) { // since we're only caching the information that we just wrote and thus won't accidentally cache any information that // isn't safe cacheRepositoryData( - BytesReference.bytes(loaded.snapshotsToXContent(XContentFactory.jsonBuilder(), Version.CURRENT)), + BytesReferenceUtil.bytes(loaded.snapshotsToXContent(XContentFactory.jsonBuilder(), Version.CURRENT)), genToLoad ); } @@ -2050,7 +2051,7 @@ public void onFailure(Exception e) { } final String indexBlob = INDEX_FILE_PREFIX + Long.toString(newGen); logger.debug("Repository [{}] writing new index generational blob [{}]", metadata.name(), indexBlob); - final BytesReference serializedRepoData = BytesReference.bytes( + final BytesReference serializedRepoData = BytesReferenceUtil.bytes( newRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(), version) ); writeAtomic(blobContainer(), indexBlob, serializedRepoData, true); diff --git a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java index a5af9226ad831..f3a9b7a4ee92e 100644 --- a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java +++ b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java @@ -40,9 +40,9 @@ import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchStatusException; -import org.opensearch.ExceptionsHelper; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -73,7 +73,7 @@ public class BytesRestResponse extends RestResponse { * Creates a new response based on {@link XContentBuilder}. */ public BytesRestResponse(RestStatus status, XContentBuilder builder) { - this(status, builder.contentType().mediaType(), BytesReference.bytes(builder)); + this(status, builder.contentType().mediaType(), BytesReferenceUtil.bytes(builder)); } /** @@ -107,7 +107,7 @@ public BytesRestResponse(RestStatus status, String contentType, BytesReference c } public BytesRestResponse(RestChannel channel, Exception e) throws IOException { - this(channel, ExceptionsHelper.status(e), e); + this(channel, BaseExceptionsHelper.status(e), e); } public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) throws IOException { @@ -131,7 +131,7 @@ public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) th this.status = status; try (XContentBuilder builder = channel.newErrorBuilder()) { build(builder, params, status, channel.detailedErrorsEnabled(), e); - this.content = BytesReference.bytes(builder); + this.content = BytesReferenceUtil.bytes(builder); this.contentType = builder.contentType().mediaType(); } if (e instanceof OpenSearchException) { @@ -189,7 +189,7 @@ public static OpenSearchStatusException errorFromXContent(XContentParser parser) XContentParser.Token token = parser.nextToken(); ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); - OpenSearchException exception = null; + BaseOpenSearchException exception = null; RestStatus status = null; String currentFieldName = null; @@ -203,7 +203,7 @@ public static OpenSearchStatusException errorFromXContent(XContentParser parser) status = RestStatus.fromCode(parser.intValue()); } } else { - exception = OpenSearchException.failureFromXContent(parser); + exception = BaseOpenSearchException.failureFromXContent(parser); } } diff --git a/server/src/main/java/org/opensearch/rest/RestRequestFilter.java b/server/src/main/java/org/opensearch/rest/RestRequestFilter.java index f24c5a15c4304..5d7d320dedd78 100644 --- a/server/src/main/java/org/opensearch/rest/RestRequestFilter.java +++ b/server/src/main/java/org/opensearch/rest/RestRequestFilter.java @@ -35,6 +35,7 @@ import org.opensearch.OpenSearchException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.support.XContentMapValues; @@ -80,7 +81,7 @@ public BytesReference content() { ); try { XContentBuilder xContentBuilder = XContentBuilder.builder(result.v1().xContent()).map(transformedSource); - filteredBytes = BytesReference.bytes(xContentBuilder); + filteredBytes = BytesReferenceUtil.bytes(xContentBuilder); } catch (IOException e) { throw new OpenSearchException("failed to parse request", e); } diff --git a/server/src/main/java/org/opensearch/script/Script.java b/server/src/main/java/org/opensearch/script/Script.java index 6580bfe8326f6..15d825d9e27e3 100644 --- a/server/src/main/java/org/opensearch/script/Script.java +++ b/server/src/main/java/org/opensearch/script/Script.java @@ -33,10 +33,10 @@ package org.opensearch.script; import org.opensearch.OpenSearchParseException; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; @@ -329,7 +329,7 @@ public static Script parse(Settings settings) { settings.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); try ( - InputStream stream = BytesReference.bytes(builder).streamInput(); + InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); XContentParser parser = JsonXContent.jsonXContent.createParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, diff --git a/server/src/main/java/org/opensearch/search/SearchHit.java b/server/src/main/java/org/opensearch/search/SearchHit.java index 3ad13c7e8b63d..e0d0493339caf 100644 --- a/server/src/main/java/org/opensearch/search/SearchHit.java +++ b/server/src/main/java/org/opensearch/search/SearchHit.java @@ -46,6 +46,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.text.Text; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.ParseField; @@ -866,7 +867,7 @@ private static BytesReference parseSourceBytes(XContentParser parser) throws IOE // pretty printing are not preserved, // it all depends on the current builder settings builder.copyCurrentStructure(parser); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } diff --git a/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java b/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java index 5a42d47662d4c..5deee600cfca5 100644 --- a/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java +++ b/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java @@ -34,8 +34,8 @@ import org.apache.lucene.index.LeafReaderContext; import org.opensearch.OpenSearchException; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.search.SearchHit; import org.opensearch.search.fetch.FetchContext; @@ -117,7 +117,7 @@ private void hitExecute(String index, FetchSourceContext fetchSourceContext, Hit builder.startObject(); builder.endObject(); } - hitContext.hit().sourceRef(BytesReference.bytes(builder)); + hitContext.hit().sourceRef(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new OpenSearchException("Error filtering source", e); } diff --git a/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java b/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java index e2599fd78908c..bd38dd2618c81 100644 --- a/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java +++ b/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java @@ -14,6 +14,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.ParseField; @@ -43,7 +44,7 @@ public class PipelineConfiguration extends AbstractDiffable { XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent()); contentBuilder.generator().copyCurrentStructure(parser); - builder.setConfig(BytesReference.bytes(contentBuilder), contentBuilder.contentType()); + builder.setConfig(BytesReferenceUtil.bytes(contentBuilder), contentBuilder.contentType()); }, new ParseField("config"), ObjectParser.ValueType.OBJECT); } diff --git a/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java b/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java index 314adf6b8e40c..2f3c7ccef689b 100644 --- a/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java +++ b/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java @@ -32,6 +32,7 @@ package org.opensearch.search.suggest.completion; import org.opensearch.OpenSearchParseException; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -113,7 +114,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder> ids = new HashMap<>(); + Map> ids = new HashMap<>(); ids.put(0, org.opensearch.index.snapshots.IndexShardSnapshotFailedException.class); ids.put(1, org.opensearch.search.dfs.DfsPhaseExecutionException.class); ids.put(2, org.opensearch.common.util.CancellableThreads.ExecutionCancelledException.class); @@ -886,8 +886,8 @@ public void testIds() { ids.put(170, SearchPipelineProcessingException.class); ids.put(10001, IndexCreateBlockException.class); - Map, Integer> reverse = new HashMap<>(); - for (Map.Entry> entry : ids.entrySet()) { + Map, Integer> reverse = new HashMap<>(); + for (Map.Entry> entry : ids.entrySet()) { if (entry.getValue() != null) { reverse.put(entry.getValue(), entry.getKey()); } @@ -902,7 +902,7 @@ public void testIds() { assertEquals((int) reverse.get(tuple.v2()), (int) tuple.v1()); } - for (Map.Entry> entry : ids.entrySet()) { + for (Map.Entry> entry : ids.entrySet()) { if (entry.getValue() != null) { assertEquals((int) entry.getKey(), OpenSearchException.getId(entry.getValue())); } diff --git a/server/src/test/java/org/opensearch/ExceptionsHelperTests.java b/server/src/test/java/org/opensearch/ExceptionsHelperTests.java index 395c5ec14c8a3..2761d59958a84 100644 --- a/server/src/test/java/org/opensearch/ExceptionsHelperTests.java +++ b/server/src/test/java/org/opensearch/ExceptionsHelperTests.java @@ -108,9 +108,12 @@ private void assertError(final Throwable cause, final Error error) { } public void testStatus() { - assertThat(ExceptionsHelper.status(new IllegalArgumentException("illegal")), equalTo(RestStatus.BAD_REQUEST)); - assertThat(ExceptionsHelper.status(new JsonParseException(null, "illegal")), equalTo(RestStatus.BAD_REQUEST)); - assertThat(ExceptionsHelper.status(new OpenSearchRejectedExecutionException("rejected")), equalTo(RestStatus.TOO_MANY_REQUESTS)); + assertThat(BaseExceptionsHelper.status(new IllegalArgumentException("illegal")), equalTo(RestStatus.BAD_REQUEST)); + assertThat(BaseExceptionsHelper.status(new JsonParseException(null, "illegal")), equalTo(RestStatus.BAD_REQUEST)); + assertThat( + BaseExceptionsHelper.status(new OpenSearchRejectedExecutionException("rejected")), + equalTo(RestStatus.TOO_MANY_REQUESTS) + ); } public void testSummaryMessage() { diff --git a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java index d584e9130e20e..73095328fd063 100644 --- a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java +++ b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java @@ -46,6 +46,7 @@ import org.opensearch.common.ParsingException; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; @@ -514,10 +515,10 @@ public void testToXContentWithHeadersAndMetadata() throws IOException { assertExceptionAsJson(e, expectedJson); - OpenSearchException parsed; + BaseOpenSearchException parsed; try (XContentParser parser = createParser(XContentType.JSON.xContent(), expectedJson)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = OpenSearchException.fromXContent(parser); + parsed = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -531,13 +532,13 @@ public void testToXContentWithHeadersAndMetadata() throws IOException { assertEquals(parsed.getMetadata("opensearch.metadata_foo_0").get(0), "foo_0"); assertEquals(parsed.getMetadata("opensearch.metadata_foo_1").get(0), "foo_1"); - OpenSearchException cause = (OpenSearchException) parsed.getCause(); + BaseOpenSearchException cause = (BaseOpenSearchException) parsed.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=bar]"); - cause = (OpenSearchException) cause.getCause(); + cause = (BaseOpenSearchException) cause.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=baz]"); - cause = (OpenSearchException) cause.getCause(); + cause = (BaseOpenSearchException) cause.getCause(); assertEquals( cause.getMessage(), "OpenSearch exception [type=cluster_block_exception, reason=blocked by: [SERVICE_UNAVAILABLE/2/no cluster-manager];]" @@ -554,10 +555,10 @@ public void testFromXContent() throws IOException { .endObject(); builder = shuffleXContent(builder); - OpenSearchException parsed; - try (XContentParser parser = createParser(xContent, BytesReference.bytes(builder))) { + BaseOpenSearchException parsed; + try (XContentParser parser = createParser(xContent, BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = OpenSearchException.fromXContent(parser); + parsed = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -576,10 +577,10 @@ public void testFromXContentWithCause() throws IOException { XContentBuilder builder = XContentBuilder.builder(xContent).startObject().value(e).endObject(); builder = shuffleXContent(builder); - OpenSearchException parsed; + BaseOpenSearchException parsed; try (XContentParser parser = createParser(builder)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = OpenSearchException.fromXContent(parser); + parsed = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -587,14 +588,14 @@ public void testFromXContentWithCause() throws IOException { assertNotNull(parsed); assertEquals(parsed.getMessage(), "OpenSearch exception [type=exception, reason=foo]"); - OpenSearchException cause = (OpenSearchException) parsed.getCause(); + BaseOpenSearchException cause = (BaseOpenSearchException) parsed.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=bar]"); - cause = (OpenSearchException) cause.getCause(); + cause = (BaseOpenSearchException) cause.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=baz]"); - cause = (OpenSearchException) cause.getCause(); + cause = (BaseOpenSearchException) cause.getCause(); assertEquals( cause.getMessage(), "OpenSearch exception [type=routing_missing_exception, reason=routing is required for [_test]/[_id]]" @@ -624,10 +625,10 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { XContentBuilder builder = XContentBuilder.builder(xContent).startObject().value(foo).endObject(); builder = shuffleXContent(builder); - OpenSearchException parsed; + BaseOpenSearchException parsed; try (XContentParser parser = createParser(builder)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = OpenSearchException.fromXContent(parser); + parsed = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -639,7 +640,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { assertThat(parsed.getMetadataKeys(), hasSize(1)); assertThat(parsed.getMetadata("opensearch.foo_0"), hasItem("foo0")); - OpenSearchException cause = (OpenSearchException) parsed.getCause(); + BaseOpenSearchException cause = (BaseOpenSearchException) parsed.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=bar]"); assertThat(cause.getHeaderKeys(), hasSize(1)); assertThat(cause.getHeader("bar_1"), hasItem("bar1")); @@ -647,7 +648,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { assertThat(cause.getMetadata("opensearch.bar_0"), hasItem("bar0")); assertThat(cause.getMetadata("opensearch.bar_2"), hasItem("bar2")); - cause = (OpenSearchException) cause.getCause(); + cause = (BaseOpenSearchException) cause.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=baz]"); assertThat(cause.getHeaderKeys(), hasSize(2)); assertThat(cause.getHeader("baz_0"), hasItem("baz0")); @@ -656,7 +657,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { assertThat(cause.getMetadata("opensearch.baz_1"), hasItem("baz1")); assertThat(cause.getMetadata("opensearch.baz_3"), hasItem("baz3")); - cause = (OpenSearchException) cause.getCause(); + cause = (BaseOpenSearchException) cause.getCause(); assertEquals( cause.getMessage(), "OpenSearch exception [type=routing_missing_exception, reason=routing is required for [_test]/[_id]]" @@ -705,14 +706,14 @@ public void testFromXContentWithIgnoredMetadataAndHeaders() throws IOException { .endObject() .endObject(); try (XContentBuilder shuffledBuilder = shuffleXContent(builder)) { - originalBytes = BytesReference.bytes(shuffledBuilder); + originalBytes = BytesReferenceUtil.bytes(shuffledBuilder); } } - OpenSearchException parsedException; + BaseOpenSearchException parsedException; try (XContentParser parser = createParser(xContent, originalBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsedException = OpenSearchException.fromXContent(parser); + parsedException = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -731,7 +732,7 @@ public void testThrowableToAndFromXContent() throws IOException { final Tuple exceptions = randomExceptions(); final Throwable throwable = exceptions.v1(); - final OpenSearchException expected = exceptions.v2(); + final BaseOpenSearchException expected = exceptions.v2(); int suppressedCount = randomBoolean() ? 0 : between(1, 5); for (int i = 0; i < suppressedCount; i++) { final Tuple suppressed = randomExceptions(); @@ -744,10 +745,10 @@ public void testThrowableToAndFromXContent() throws IOException { return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); - OpenSearchException parsedException; + BaseOpenSearchException parsedException; try (XContentParser parser = createParser(xContent, throwableBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsedException = OpenSearchException.fromXContent(parser); + parsedException = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -758,7 +759,7 @@ public void testThrowableToAndFromXContent() throws IOException { builder.startObject(); BaseExceptionsHelper.generateThrowableXContent(builder, ToXContent.EMPTY_PARAMS, throwable); builder.endObject(); - throwableBytes = BytesReference.bytes(builder); + throwableBytes = BytesReferenceUtil.bytes(builder); try (XContentParser parser = createParser(xContent, throwableBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); List keys = new ArrayList<>(parser.mapOrdered().keySet()); @@ -776,11 +777,11 @@ public void testUnknownFailureToAndFromXContent() throws IOException { return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); - OpenSearchException parsedFailure; + BaseOpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - parsedFailure = OpenSearchException.failureFromXContent(parser); + parsedFailure = BaseOpenSearchException.failureFromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } @@ -801,14 +802,14 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException { }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); try (XContentParser parser = createParser(xContent, failureBytes)) { - failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); + failureBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } - OpenSearchException parsedFailure; + BaseOpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - parsedFailure = OpenSearchException.failureFromXContent(parser); + parsedFailure = BaseOpenSearchException.failureFromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } @@ -840,7 +841,7 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { case 1: // Simple opensearch exception with headers (other metadata of type number are not parsed) failure = new ParsingException(3, 2, "B", null); - ((OpenSearchException) failure).addHeader("header_name", "0", "1"); + ((BaseOpenSearchException) failure).addHeader("header_name", "0", "1"); expected = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=B]"); expected.addHeader("header_name", "0", "1"); suppressed = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=B]"); @@ -955,14 +956,14 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); try (XContentParser parser = createParser(xContent, failureBytes)) { - failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); + failureBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } - OpenSearchException parsedFailure; + BaseOpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - parsedFailure = OpenSearchException.failureFromXContent(parser); + parsedFailure = BaseOpenSearchException.failureFromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } @@ -988,7 +989,7 @@ private static void assertExceptionAsJson(Exception e, String expectedJson) thro }, expectedJson); } - public static void assertDeepEquals(OpenSearchException expected, OpenSearchException actual) { + public static void assertDeepEquals(BaseOpenSearchException expected, BaseOpenSearchException actual) { do { if (expected == null) { assertNull(actual); @@ -1011,12 +1012,12 @@ public static void assertDeepEquals(OpenSearchException expected, OpenSearchExce assertNotNull(actualSuppressed); assertEquals(expectedSuppressed.length, actualSuppressed.length); for (int i = 0; i < expectedSuppressed.length; i++) { - assertDeepEquals((OpenSearchException) expectedSuppressed[i], (OpenSearchException) actualSuppressed[i]); + assertDeepEquals((BaseOpenSearchException) expectedSuppressed[i], (BaseOpenSearchException) actualSuppressed[i]); } } - expected = (OpenSearchException) expected.getCause(); - actual = (OpenSearchException) actual.getCause(); + expected = (BaseOpenSearchException) expected.getCause(); + actual = (BaseOpenSearchException) actual.getCause(); if (expected == null) { assertNull(actual); } diff --git a/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java b/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java index d867881c76c20..dc1af8ba7f6e3 100644 --- a/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java +++ b/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java @@ -34,7 +34,7 @@ import org.opensearch.action.DocWriteResponse.Result; import org.opensearch.action.support.replication.ReplicationResponse.ShardInfo; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -112,14 +112,14 @@ public void testToXContentDoesntIncludeForcedRefreshUnlessForced() throws IOExce response.setForcedRefresh(false); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { assertThat(parser.map(), not(hasKey("forced_refresh"))); } } response.setForcedRefresh(true); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { assertThat(parser.map(), hasEntry("forced_refresh", true)); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index c071b1622dd60..34ab2f2126f87 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -51,11 +51,11 @@ import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -772,6 +772,6 @@ private Map serialize(ListTasksResponse response, boolean byPare builder.endObject(); builder.flush(); logger.info(Strings.toString(builder)); - return XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + return XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java index 284e6f538adb9..d0f98b6e2f4be 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java @@ -8,8 +8,8 @@ package org.opensearch.action.admin.cluster.remotestore.restore; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -70,7 +70,7 @@ public void testSource() throws IOException { RestoreRemoteStoreRequest original = createTestInstance(); XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new ToXContent.MapParams(Collections.emptyMap())); XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput()); + .createParser(NamedXContentRegistry.EMPTY, null, BytesReferenceUtil.bytes(builder).streamInput()); Map map = parser.mapOrdered(); RestoreRemoteStoreRequest processed = new RestoreRemoteStoreRequest(); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java index 7d8e1ad5c7016..6ec083370a658 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java @@ -9,7 +9,7 @@ package org.opensearch.action.admin.cluster.remotestore.stats; import org.opensearch.action.support.DefaultShardOperationFailedException; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.XContentBuilder; @@ -56,8 +56,11 @@ public void testSerialization() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder(); statsResponse.toXContent(builder, EMPTY_PARAMS); - Map jsonResponseObject = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()) - .v2(); + Map jsonResponseObject = XContentHelper.convertToMap( + BytesReferenceUtil.bytes(builder), + false, + builder.contentType() + ).v2(); ArrayList> statsObjectArray = (ArrayList>) jsonResponseObject.get("stats"); assertEquals(statsObjectArray.size(), 1); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java index 94d2eae31c040..a3228b1627492 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java @@ -8,9 +8,9 @@ package org.opensearch.action.admin.cluster.remotestore.stats; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.XContentBuilder; @@ -50,7 +50,7 @@ public void testXContentBuilder() throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); stats.toXContent(builder, EMPTY_PARAMS); - Map jsonObject = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map jsonObject = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); compareStatsResponse(jsonObject, pressureTrackerStats); } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java index 203bfd0db284a..6d9d9f1d2f07b 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java @@ -31,8 +31,8 @@ package org.opensearch.action.admin.cluster.repositories.put; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -71,7 +71,7 @@ public void testCreateRepositoryToXContent() throws IOException { request.toXContent(builder, new ToXContent.MapParams(mapParams)); builder.flush(); - Map outputMap = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map outputMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); assertThat(outputMap.get("name"), equalTo(request.name())); assertThat(outputMap.get("verify"), equalTo(request.verify())); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java index b057b583caeb8..9ae8a55baaa93 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java @@ -40,12 +40,12 @@ import org.opensearch.cluster.routing.allocation.command.AllocationCommand; import org.opensearch.cluster.routing.allocation.command.CancelAllocationCommand; import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.network.NetworkModule; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -244,7 +244,7 @@ private RestRequest toRestRequest(ClusterRerouteRequest original) throws IOExcep FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry()); requestBuilder.withParams(params); if (hasBody) { - requestBuilder.withContent(BytesReference.bytes(builder), XContentType.fromMediaType(builder.contentType())); + requestBuilder.withContent(BytesReferenceUtil.bytes(builder), XContentType.fromMediaType(builder.contentType())); } return requestBuilder.build(); } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java index fad5155d0fd61..70cc8039df784 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java @@ -33,6 +33,7 @@ package org.opensearch.action.admin.cluster.settings; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParseException; import org.opensearch.core.xcontent.XContentParser; @@ -64,7 +65,7 @@ private void doFromXContentTestWithRandomFields(boolean addRandomFields) throws if (addRandomFields) { String unsupportedField = "unsupported_field"; - BytesReference mutated = BytesReference.bytes( + BytesReference mutated = BytesReferenceUtil.bytes( XContentTestUtils.insertIntoXContent( xContentType.xContent(), originalBytes, diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java index 6083e74190e1b..6fac686e3239a 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java @@ -36,8 +36,8 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.action.support.IndicesOptions.Option; import org.opensearch.action.support.IndicesOptions.WildcardStates; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent.MapParams; import org.opensearch.core.xcontent.XContentBuilder; @@ -125,7 +125,7 @@ public void testToXContent() throws IOException { XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new MapParams(Collections.emptyMap())); XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput()); + .createParser(NamedXContentRegistry.EMPTY, null, BytesReferenceUtil.bytes(builder).streamInput()); Map map = parser.mapOrdered(); CreateSnapshotRequest processed = new CreateSnapshotRequest((String) map.get("repository"), (String) map.get("snapshot")); processed.waitForCompletion(original.waitForCompletion()); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java index 737e7b2e4887b..8c4f35edde009 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java @@ -33,8 +33,8 @@ package org.opensearch.action.admin.cluster.snapshots.restore; import org.opensearch.action.support.IndicesOptions; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -138,7 +138,7 @@ public void testSource() throws IOException { original.snapshotUuid(null); // cannot be set via the REST API XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new ToXContent.MapParams(Collections.emptyMap())); XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput()); + .createParser(NamedXContentRegistry.EMPTY, null, BytesReferenceUtil.bytes(builder).streamInput()); Map map = parser.mapOrdered(); // we will only restore properties from the map that are contained in the request body. All other diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java index de5cad93980eb..20c11f3f5c490 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java @@ -36,6 +36,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; @@ -76,7 +77,7 @@ public void testToXContent() throws IOException { builder.startObject("script").field("lang", "painless").field("source", "Math.log(_score * 2) + params.multiplier").endObject(); builder.endObject(); - BytesReference expectedRequestBody = BytesReference.bytes(builder); + BytesReference expectedRequestBody = BytesReferenceUtil.bytes(builder); PutStoredScriptRequest request = new PutStoredScriptRequest(); request.id("test1"); @@ -87,7 +88,7 @@ public void testToXContent() throws IOException { request.toXContent(requestBuilder, ToXContent.EMPTY_PARAMS); requestBuilder.endObject(); - BytesReference actualRequestBody = BytesReference.bytes(requestBuilder); + BytesReference actualRequestBody = BytesReferenceUtil.bytes(requestBuilder); assertEquals(expectedRequestBody, actualRequestBody); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java index 00545898ad3e4..e6205fe692bd7 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java @@ -33,8 +33,8 @@ package org.opensearch.action.admin.indices.analyze; import org.opensearch.action.admin.indices.analyze.AnalyzeAction.AnalyzeToken; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable.Reader; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -68,7 +68,8 @@ public void testNullResponseToXContent() throws IOException { AnalyzeAction.Response response = new AnalyzeAction.Response(null, detail); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - Map converted = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map converted = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()) + .v2(); List> tokenfiltersValue = (List>) ((Map) converted.get("detail")).get( "tokenfilters" ); diff --git a/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java index 176c3163697c1..345a9bbfe3795 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java @@ -43,6 +43,7 @@ import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -187,7 +188,7 @@ public void testUnknownFields() throws IOException { builder.endObject(); } builder.endObject(); - BytesReference mutated = XContentTestUtils.insertRandomFields(xContentType, BytesReference.bytes(builder), null, random()); + BytesReference mutated = XContentTestUtils.insertRandomFields(xContentType, BytesReferenceUtil.bytes(builder), null, random()); expectThrows(XContentParseException.class, () -> request.fromXContent(createParser(xContentType.xContent(), mutated))); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java index 2d353340aa5b0..ce33873a746cc 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java @@ -38,6 +38,7 @@ import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.ImmutableOpenIntMap; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -102,7 +103,7 @@ public void testBasicSerialization() throws Exception { contentBuilder.startObject(); storesResponse.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - BytesReference bytes = BytesReference.bytes(contentBuilder); + BytesReference bytes = BytesReferenceUtil.bytes(contentBuilder); try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) { Map map = parser.map(); diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java index 88c6b466059bc..b87363525c841 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java @@ -32,8 +32,9 @@ package org.opensearch.action.bulk; +import org.opensearch.BaseExceptionsHelper; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; -import org.opensearch.ExceptionsHelper; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.bulk.BulkItemResponse.Failure; @@ -43,6 +44,7 @@ import org.opensearch.action.update.UpdateResponseTests; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -109,14 +111,14 @@ public void testFailureToAndFromXContent() throws IOException { Exception bulkItemCause = (Exception) exceptions.v1(); Failure bulkItemFailure = new Failure(index, id, bulkItemCause); BulkItemResponse bulkItemResponse = new BulkItemResponse(itemId, opType, bulkItemFailure); - Failure expectedBulkItemFailure = new Failure(index, id, exceptions.v2(), ExceptionsHelper.status(bulkItemCause)); + Failure expectedBulkItemFailure = new Failure(index, id, exceptions.v2(), BaseExceptionsHelper.status(bulkItemCause)); BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(itemId, opType, expectedBulkItemFailure); BytesReference originalBytes = toShuffledXContent(bulkItemResponse, xContentType, ToXContent.EMPTY_PARAMS, randomBoolean()); // Shuffle the XContent fields if (randomBoolean()) { try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - originalBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); + originalBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } } @@ -146,7 +148,7 @@ public static void assertBulkItemResponse(BulkItemResponse expected, BulkItemRes assertEquals(expectedFailure.getMessage(), actualFailure.getMessage()); assertEquals(expectedFailure.getStatus(), actualFailure.getStatus()); - assertDeepEquals((OpenSearchException) expectedFailure.getCause(), (OpenSearchException) actualFailure.getCause()); + assertDeepEquals((BaseOpenSearchException) expectedFailure.getCause(), (BaseOpenSearchException) actualFailure.getCause()); } else { DocWriteResponse expectedDocResponse = expected.getResponse(); DocWriteResponse actualDocResponse = expected.getResponse(); diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java index ef930b61f890b..f7fd434b2fb26 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java @@ -32,8 +32,8 @@ package org.opensearch.action.bulk; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; -import org.opensearch.ExceptionsHelper; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.delete.DeleteResponseTests; @@ -95,7 +95,7 @@ public void testToAndFromXContent() throws IOException { expectedBulkItems[i] = new BulkItemResponse( i, opType, - new BulkItemResponse.Failure(index, id, failures.v2(), ExceptionsHelper.status(bulkItemCause)) + new BulkItemResponse.Failure(index, id, failures.v2(), BaseExceptionsHelper.status(bulkItemCause)) ); } } diff --git a/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java b/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java index cada565748de8..d2db358a66b47 100644 --- a/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java +++ b/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java @@ -34,9 +34,9 @@ import org.apache.lucene.search.Explanation; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.document.DocumentField; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -117,7 +117,7 @@ public void testToXContent() throws IOException { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); response.toXContent(builder, ToXContent.EMPTY_PARAMS); - String generatedResponse = BytesReference.bytes(builder).utf8ToString().replaceAll("\\s+", ""); + String generatedResponse = BytesReferenceUtil.bytes(builder).utf8ToString().replaceAll("\\s+", ""); String expectedResponse = ("{\n" + " \"_index\":\"index\",\n" diff --git a/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java b/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java index 253252d76bbc9..664f4a64b596e 100644 --- a/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java +++ b/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java @@ -32,8 +32,8 @@ package org.opensearch.action.fieldcaps; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -128,7 +128,7 @@ public void testToXContent() throws IOException { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); response.toXContent(builder, ToXContent.EMPTY_PARAMS); - String generatedResponse = BytesReference.bytes(builder).utf8ToString(); + String generatedResponse = BytesReferenceUtil.bytes(builder).utf8ToString(); assertEquals( ("{" + " \"indices\": null," diff --git a/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java b/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java index 1184b05461025..149523f0f5072 100644 --- a/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java +++ b/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java @@ -47,8 +47,8 @@ import org.opensearch.cluster.routing.OperationRouting; import org.opensearch.cluster.routing.ShardIterator; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.AtomicArray; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentFactory; @@ -128,7 +128,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") @@ -153,7 +153,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") diff --git a/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java b/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java index 68bb523d594c0..4b085d57a9daa 100644 --- a/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java @@ -32,8 +32,8 @@ package org.opensearch.action.ingest; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -68,7 +68,7 @@ private PipelineConfiguration createRandomPipeline(String pipelineId) throws IOE builder.field("value", value); builder.endObject(); builder.endObject(); - return new PipelineConfiguration(pipelineId, BytesReference.bytes(builder), builder.contentType()); + return new PipelineConfiguration(pipelineId, BytesReferenceUtil.bytes(builder), builder.contentType()); } private Map createPipelineConfigMap() throws IOException { @@ -88,7 +88,7 @@ public void testXContentDeserialization() throws IOException { XContentParser parser = builder.generator() .contentType() .xContent() - .createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(builder).streamInput()); + .createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReferenceUtil.bytes(builder).streamInput()); GetPipelineResponse parsedResponse = GetPipelineResponse.fromXContent(parser); List actualPipelines = response.pipelines(); List parsedPipelines = parsedResponse.pipelines(); diff --git a/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java b/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java index 8a9eda29a1d7f..a84e065df9578 100644 --- a/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java @@ -36,6 +36,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; @@ -75,9 +76,9 @@ public void testToXContent() throws IOException { // End first processor pipelineBuilder.endArray(); pipelineBuilder.endObject(); - PutPipelineRequest request = new PutPipelineRequest("1", BytesReference.bytes(pipelineBuilder), xContentType); + PutPipelineRequest request = new PutPipelineRequest("1", BytesReferenceUtil.bytes(pipelineBuilder), xContentType); XContentBuilder requestBuilder = XContentBuilder.builder(xContentType.xContent()); - BytesReference actualRequestBody = BytesReference.bytes(request.toXContent(requestBuilder, ToXContent.EMPTY_PARAMS)); - assertEquals(BytesReference.bytes(pipelineBuilder), actualRequestBody); + BytesReference actualRequestBody = BytesReferenceUtil.bytes(request.toXContent(requestBuilder, ToXContent.EMPTY_PARAMS)); + assertEquals(BytesReferenceUtil.bytes(pipelineBuilder), actualRequestBody); } } diff --git a/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java b/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java index da3f9687ae5cf..a95e21e7a85aa 100644 --- a/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -152,7 +153,8 @@ public void testToXContent() throws IOException { builder.startObject(); writeableIngestDocument.toXContent(builder, EMPTY_PARAMS); builder.endObject(); - Map toXContentMap = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map toXContentMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()) + .v2(); Map toXContentDoc = (Map) toXContentMap.get("doc"); Map toXContentSource = (Map) toXContentDoc.get("_source"); diff --git a/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java b/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java index e65101838884a..08e82a71986f6 100644 --- a/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java +++ b/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java @@ -36,10 +36,10 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.common.CheckedBiConsumer; import org.opensearch.common.CheckedRunnable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.unit.TimeValue; @@ -546,7 +546,7 @@ private void assertExpandWildcardsValue(IndicesOptions options, String expectedV MultiSearchRequest.writeSearchRequestParams(request, builder); Map map = XContentHelper.convertToMap( XContentType.JSON.xContent(), - BytesReference.bytes(builder).streamInput(), + BytesReferenceUtil.bytes(builder).streamInput(), false ); final String value = (String) map.get("expand_wildcards"); diff --git a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java index 169f2d47743d1..bed8bd34f20f6 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java @@ -32,7 +32,7 @@ package org.opensearch.action.search; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.TimestampParsingException; import org.opensearch.common.ParsingException; @@ -136,10 +136,10 @@ public void testToAndFromXContent() throws IOException { BytesReference exceptionBytes = toShuffledXContent(actual, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); - OpenSearchException parsedException; + BaseOpenSearchException parsedException; try (XContentParser parser = createParser(xContent, exceptionBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsedException = OpenSearchException.fromXContent(parser); + parsedException = BaseOpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } diff --git a/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java b/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java index ee96ce5ad505c..49d6a49a3dff5 100644 --- a/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java @@ -40,9 +40,9 @@ import org.opensearch.OpenSearchException; import org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -143,7 +143,7 @@ public void testFromXContent() throws IOException { .endObject(); builder = shuffleXContent(builder); DefaultShardOperationFailedException parsed; - try (XContentParser parser = createParser(xContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xContent, BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); parsed = DefaultShardOperationFailedException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); diff --git a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java index 37084fada85ae..6f00b4ef2cc57 100644 --- a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java +++ b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java @@ -38,6 +38,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent.MapParams; import org.opensearch.core.xcontent.XContentBuilder; @@ -428,7 +429,7 @@ public void testFromXContentWithWildcardSpecialValues() throws IOException { builder.field("ignore_unavailable", ignoreUnavailable); builder.field("allow_no_indices", allowNoIndices); builder.endObject(); - xContentBytes = BytesReference.bytes(builder); + xContentBytes = BytesReferenceUtil.bytes(builder); } IndicesOptions fromXContentOptions; @@ -447,7 +448,7 @@ public void testFromXContentWithWildcardSpecialValues() throws IOException { builder.field("ignore_unavailable", ignoreUnavailable); builder.field("allow_no_indices", allowNoIndices); builder.endObject(); - xContentBytes = BytesReference.bytes(builder); + xContentBytes = BytesReferenceUtil.bytes(builder); } try (XContentParser parser = type.xContent().createParser(NamedXContentRegistry.EMPTY, null, xContentBytes.streamInput())) { @@ -465,7 +466,7 @@ private BytesReference toXContentBytes(IndicesOptions indicesOptions, XContentTy builder.startObject(); indicesOptions.toXContent(builder, new MapParams(Collections.emptyMap())); builder.endObject(); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } } diff --git a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java index 7f5a1925043dc..1b51c00fbc1dd 100644 --- a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java +++ b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java @@ -32,6 +32,7 @@ package org.opensearch.action.support.replication; +import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.support.replication.ReplicationResponse.ShardInfo; import org.opensearch.common.Strings; @@ -39,6 +40,7 @@ import org.opensearch.common.breaker.CircuitBreakingException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -112,7 +114,7 @@ public void testShardInfoToAndFromXContent() throws IOException { // Shuffle the XContent fields if (randomBoolean()) { try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - originalBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); + originalBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } } @@ -152,7 +154,7 @@ public static void assertShardInfo(ShardInfo expected, ShardInfo actual) { assertEquals(expectedFailure.primary(), actualFailure.primary()); OpenSearchException expectedCause = (OpenSearchException) expectedFailure.getCause(); - OpenSearchException actualCause = (OpenSearchException) actualFailure.getCause(); + BaseOpenSearchException actualCause = (BaseOpenSearchException) actualFailure.getCause(); assertDeepEquals(expectedCause, actualCause); } } diff --git a/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java b/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java index b62050a1b8050..5a093ac5969ba 100644 --- a/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java +++ b/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java @@ -48,8 +48,8 @@ import org.opensearch.cluster.routing.OperationRouting; import org.opensearch.cluster.routing.ShardIterator; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.AtomicArray; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentFactory; @@ -129,7 +129,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") @@ -154,7 +154,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") diff --git a/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java b/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java index d94ca9f1e3068..face747be9412 100644 --- a/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java +++ b/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java @@ -42,6 +42,7 @@ import org.opensearch.common.document.DocumentField; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -490,7 +491,7 @@ public void testToAndFromXContent() throws IOException { if (randomBoolean()) { try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - originalBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); + originalBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } } diff --git a/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java b/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java index 97865d3845c2c..335f27f37aabc 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java @@ -33,8 +33,8 @@ import org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion; import org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -134,7 +134,7 @@ public void testVotingTombstoneXContent() throws IOException { final XContentBuilder builder = JsonXContent.contentBuilder(); originalTombstone.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { final VotingConfigExclusion fromXContentTombstone = VotingConfigExclusion.fromXContent(parser); assertThat(originalTombstone, equalTo(fromXContentTombstone)); } @@ -226,7 +226,7 @@ public void testXContent() throws IOException { originalMeta.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { final CoordinationMetadata fromXContentMeta = CoordinationMetadata.fromXContent(parser); assertThat(originalMeta, equalTo(fromXContentMeta)); } diff --git a/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java b/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java index 853ead71b30fb..9c9a92fc746af 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java @@ -38,7 +38,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.common.UUIDs; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -90,7 +90,7 @@ private void runLoadStateTest(boolean hasMissingCustoms, boolean preserveUnknown XContentParser parser = createParser( hasMissingCustoms ? OpenSearchNodeCommand.namedXContentRegistry : xContentRegistry(), JsonXContent.jsonXContent, - BytesReference.bytes(builder) + BytesReferenceUtil.bytes(builder) ) ) { loadedMetadata = Metadata.fromXContent(parser); diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java index f6253023fbdd5..16808c97b5a95 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java @@ -34,9 +34,9 @@ import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentOpenSearchExtension; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.ToXContent; @@ -93,7 +93,7 @@ public void testXContent() throws IOException { ) ); } - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); parser.nextToken(); // the beginning of the parser assertThat(IndexGraveyard.fromXContent(parser), equalTo(graveyard)); } diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java index 38fb1a657b9e8..a724de869e511 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java @@ -37,7 +37,6 @@ import org.opensearch.action.admin.indices.rollover.MaxSizeCondition; import org.opensearch.action.admin.indices.rollover.RolloverInfo; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; @@ -45,6 +44,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -125,7 +125,7 @@ public void testIndexMetadataSerialization() throws IOException { builder.startObject(); IndexMetadata.FORMAT.toXContent(builder, metadata); builder.endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); final IndexMetadata fromXContentMeta = IndexMetadata.fromXContent(parser); assertEquals( "expected: " diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java index d5de57806282d..f68682567c5f0 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java @@ -34,6 +34,7 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -84,7 +85,7 @@ public void testIndexTemplateMetadataXContentRoundTrip() throws Exception { builder.startObject(); IndexTemplateMetadata.Builder.toXContentWithTypes(indexTemplateMetadata, builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - templateBytesRoundTrip = BytesReference.bytes(builder); + templateBytesRoundTrip = BytesReferenceUtil.bytes(builder); } final IndexTemplateMetadata indexTemplateMetadataRoundTrip; diff --git a/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java b/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java index ce8a7826e605b..60f7eae0084c7 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -124,7 +125,7 @@ public void testXContent() throws IOException { builder.startObject(); Manifest.FORMAT.toXContent(builder, state); builder.endObject(); - BytesReference bytes = BytesReference.bytes(builder); + BytesReference bytes = BytesReferenceUtil.bytes(builder); try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) { assertThat(Manifest.fromXContent(parser), equalTo(state)); } diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java index a744c181ee341..c6422a4f3b4c7 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java @@ -46,6 +46,7 @@ import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -478,7 +479,7 @@ public void testResolveWriteIndexRouting() { } public void testUnknownFieldClusterMetadata() throws IOException { - BytesReference metadata = BytesReference.bytes( + BytesReference metadata = BytesReferenceUtil.bytes( JsonXContent.contentBuilder().startObject().startObject("meta-data").field("random", "value").endObject().endObject() ); try (XContentParser parser = createParser(JsonXContent.jsonXContent, metadata)) { @@ -490,7 +491,7 @@ public void testUnknownFieldClusterMetadata() throws IOException { } public void testUnknownFieldIndexMetadata() throws IOException { - BytesReference metadata = BytesReference.bytes( + BytesReference metadata = BytesReferenceUtil.bytes( JsonXContent.contentBuilder().startObject().startObject("index_name").field("random", "value").endObject().endObject() ); try (XContentParser parser = createParser(JsonXContent.jsonXContent, metadata)) { @@ -520,7 +521,7 @@ public void testXContentWithIndexGraveyard() throws IOException { builder.startObject(); Metadata.FORMAT.toXContent(builder, originalMeta); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { final Metadata fromXContentMeta = Metadata.fromXContent(parser); assertThat(fromXContentMeta.indexGraveyard(), equalTo(originalMeta.indexGraveyard())); } @@ -535,7 +536,7 @@ public void testXContentClusterUUID() throws IOException { builder.startObject(); Metadata.FORMAT.toXContent(builder, originalMeta); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { final Metadata fromXContentMeta = Metadata.fromXContent(parser); assertThat(fromXContentMeta.clusterUUID(), equalTo(originalMeta.clusterUUID())); assertThat(fromXContentMeta.clusterUUIDCommitted(), equalTo(originalMeta.clusterUUIDCommitted())); @@ -595,7 +596,7 @@ public void testXContentWithCoordinationMetadata() throws IOException { Metadata.FORMAT.toXContent(builder, metadata); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { final CoordinationMetadata fromXContentMeta = Metadata.fromXContent(parser).coordinationMetadata(); assertThat(fromXContentMeta, equalTo(originalMeta)); } diff --git a/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java b/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java index 0a4ef803068eb..09444c03f48a0 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java @@ -34,6 +34,7 @@ import org.opensearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.json.JsonXContent; @@ -165,7 +166,7 @@ public void testSerialization() throws IOException { if (randomBoolean()) { allocationId = AllocationId.newRelocation(allocationId); } - BytesReference bytes = BytesReference.bytes(allocationId.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)); + BytesReference bytes = BytesReferenceUtil.bytes(allocationId.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)); AllocationId parsedAllocationId = AllocationId.fromXContent(createParser(JsonXContent.jsonXContent, bytes)); assertEquals(allocationId, parsedAllocationId); } diff --git a/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java b/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java index 21f10aeb91542..ab101a7e57586 100644 --- a/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java +++ b/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java @@ -32,8 +32,8 @@ package org.opensearch.common.geo; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -150,7 +150,7 @@ public void testToMap() throws IOException { Geometry geometry = GeometryTestUtils.randomGeometry(randomBoolean()); XContentBuilder builder = XContentFactory.jsonBuilder(); GeoJson.toXContent(geometry, builder, ToXContent.EMPTY_PARAMS); - StreamInput input = BytesReference.bytes(builder).streamInput(); + StreamInput input = BytesReferenceUtil.bytes(builder).streamInput(); try ( XContentParser parser = XContentType.JSON.xContent() diff --git a/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java b/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java index f94fbb58311bf..c3b04352a5619 100644 --- a/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java +++ b/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java @@ -32,7 +32,7 @@ package org.opensearch.common.geo; import org.opensearch.common.CheckedConsumer; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -72,7 +72,7 @@ private int parsePrecision(CheckedConsumer tokenGe XContentBuilder builder = jsonBuilder().startObject(); tokenGenerator.accept(builder); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); // { assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); // field name assertTrue(parser.nextToken().isValue()); // field value diff --git a/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java b/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java index 0af60b8065588..111354f2b14db 100644 --- a/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java +++ b/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java @@ -931,7 +931,7 @@ public void testWriteCircularReferenceException() throws IOException { BytesStreamOutput prodOut = new BytesStreamOutput() { @Override - boolean failOnTooManyNestedExceptions(Throwable throwable) { + public boolean failOnTooManyNestedExceptions(Throwable throwable) { assertThat(throwable, sameInstance(rootEx)); return true; } diff --git a/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java index 6cfc63e5193a8..ffd2743b283dc 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java @@ -39,6 +39,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Constants; import org.opensearch.cluster.metadata.IndexMetadata; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; @@ -124,11 +125,11 @@ public void testContentType() throws IOException { } public void testStartEndObject() throws IOException { - expectUnclosedException(() -> BytesReference.bytes(builder().startObject())); + expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startObject())); expectUnclosedException(() -> builder().startObject().close()); expectUnclosedException(() -> Strings.toString(builder().startObject())); - expectObjectException(() -> BytesReference.bytes(builder().endObject())); + expectObjectException(() -> BytesReferenceUtil.bytes(builder().endObject())); expectObjectException(() -> builder().endObject().close()); expectObjectException(() -> Strings.toString(builder().endObject())); @@ -145,11 +146,11 @@ public void testStartEndObject() throws IOException { } public void testStartEndArray() throws IOException { - expectUnclosedException(() -> BytesReference.bytes(builder().startArray())); + expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startArray())); expectUnclosedException(() -> builder().startArray().close()); expectUnclosedException(() -> Strings.toString(builder().startArray())); - expectArrayException(() -> BytesReference.bytes(builder().endArray())); + expectArrayException(() -> BytesReferenceUtil.bytes(builder().endArray())); expectArrayException(() -> builder().endArray().close()); expectArrayException(() -> Strings.toString(builder().endArray())); @@ -162,17 +163,17 @@ public void testStartEndArray() throws IOException { } public void testField() throws IOException { - expectValueException(() -> BytesReference.bytes(builder().field("foo"))); - expectNonNullFieldException(() -> BytesReference.bytes(builder().field(null))); - expectUnclosedException(() -> BytesReference.bytes(builder().startObject().field("foo"))); + expectValueException(() -> BytesReferenceUtil.bytes(builder().field("foo"))); + expectNonNullFieldException(() -> BytesReferenceUtil.bytes(builder().field(null))); + expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startObject().field("foo"))); assertResult("{'foo':'bar'}", () -> builder().startObject().field("foo").value("bar").endObject()); } public void testNullField() throws IOException { - expectValueException(() -> BytesReference.bytes(builder().nullField("foo"))); - expectNonNullFieldException(() -> BytesReference.bytes(builder().nullField(null))); - expectUnclosedException(() -> BytesReference.bytes(builder().startObject().nullField("foo"))); + expectValueException(() -> BytesReferenceUtil.bytes(builder().nullField("foo"))); + expectNonNullFieldException(() -> BytesReferenceUtil.bytes(builder().nullField(null))); + expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startObject().nullField("foo"))); assertResult("{'foo':null}", () -> builder().startObject().nullField("foo").endObject()); } @@ -326,7 +327,7 @@ public void testBinaryField() throws Exception { assertResult("{'binary':null}", () -> builder().startObject().field("binary", (byte[]) null).endObject()); final byte[] randomBytes = randomBytes(); - BytesReference bytes = BytesReference.bytes(builder().startObject().field("binary", randomBytes).endObject()); + BytesReference bytes = BytesReferenceUtil.bytes(builder().startObject().field("binary", randomBytes).endObject()); try (XContentParser parser = createParser(xcontentType().xContent(), bytes)) { assertSame(parser.nextToken(), Token.START_OBJECT); @@ -343,7 +344,7 @@ public void testBinaryValue() throws Exception { assertResult("{'binary':null}", () -> builder().startObject().field("binary").value((byte[]) null).endObject()); final byte[] randomBytes = randomBytes(); - BytesReference bytes = BytesReference.bytes(builder().startObject().field("binary").value(randomBytes).endObject()); + BytesReference bytes = BytesReferenceUtil.bytes(builder().startObject().field("binary").value(randomBytes).endObject()); try (XContentParser parser = createParser(xcontentType().xContent(), bytes)) { assertSame(parser.nextToken(), Token.START_OBJECT); @@ -371,7 +372,7 @@ public void testBinaryValueWithOffsetLength() throws Exception { } builder.endObject(); - try (XContentParser parser = createParser(xcontentType().xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xcontentType().xContent(), BytesReferenceUtil.bytes(builder))) { assertSame(parser.nextToken(), Token.START_OBJECT); assertSame(parser.nextToken(), Token.FIELD_NAME); assertEquals(parser.currentName(), "bin"); @@ -390,7 +391,7 @@ public void testBinaryUTF8() throws Exception { builder.field("utf8").utf8Value(randomBytesRef.bytes, randomBytesRef.offset, randomBytesRef.length); builder.endObject(); - try (XContentParser parser = createParser(xcontentType().xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xcontentType().xContent(), BytesReferenceUtil.bytes(builder))) { assertSame(parser.nextToken(), Token.START_OBJECT); assertSame(parser.nextToken(), Token.FIELD_NAME); assertEquals(parser.currentName(), "utf8"); @@ -409,7 +410,7 @@ public void testText() throws Exception { final BytesReference random = new BytesArray(randomBytes()); XContentBuilder builder = builder().startObject().field("text", new Text(random)).endObject(); - try (XContentParser parser = createParser(xcontentType().xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(xcontentType().xContent(), BytesReferenceUtil.bytes(builder))) { assertSame(parser.nextToken(), Token.START_OBJECT); assertSame(parser.nextToken(), Token.FIELD_NAME); assertEquals(parser.currentName(), "text"); @@ -1192,7 +1193,7 @@ public void testNamedObject() throws IOException { b.value("test"); try ( XContentParser p = xcontentType().xContent() - .createParser(registry, LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(b).streamInput()) + .createParser(registry, LoggingDeprecationHandler.INSTANCE, BytesReferenceUtil.bytes(b).streamInput()) ) { assertEquals(test1, p.namedObject(Object.class, "test1", null)); assertEquals(test2, p.namedObject(Object.class, "test2", null)); @@ -1264,7 +1265,7 @@ public static Matcher equalToJson(String json) { private static void assertResult(String expected, Builder builder) throws IOException { // Build the XContentBuilder, convert its bytes to JSON and check it matches - assertThat(XContentHelper.convertToJson(BytesReference.bytes(builder.build()), randomBoolean()), equalToJson(expected)); + assertThat(XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder.build()), randomBoolean()), equalToJson(expected)); } private static byte[] randomBytes() throws Exception { diff --git a/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java b/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java index 70e7a776c5c30..bf8c19df05913 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.test.OpenSearchTestCase; @@ -79,7 +80,7 @@ private void testGuessType(XContentType type) throws IOException { sb.append(new String(chars)).append(content); bytes = new BytesArray(sb.toString()); } else { - bytes = BytesReference.bytes(builder); + bytes = BytesReferenceUtil.bytes(builder); } assertThat(XContentHelper.xContentType(bytes), equalTo(type)); diff --git a/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java b/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java index 4af333355c2b4..927013df4916d 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java @@ -35,10 +35,10 @@ import org.apache.lucene.util.BytesRef; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.io.PathUtils; import org.opensearch.common.io.stream.BytesStreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentOpenSearchExtension; import org.opensearch.common.xcontent.XContentFactory; @@ -191,7 +191,7 @@ public void testWritingBinaryToStream() throws Exception { public void testByteConversion() throws Exception { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.startObject().field("test_name", (Byte) (byte) 120).endObject(); - assertThat(BytesReference.bytes(builder).utf8ToString(), equalTo("{\"test_name\":120}")); + assertThat(BytesReferenceUtil.bytes(builder).utf8ToString(), equalTo("{\"test_name\":120}")); } public void testDateTypesConversion() throws Exception { @@ -235,7 +235,7 @@ public void testCopyCurrentStructure() throws Exception { XContentBuilder filterBuilder = null; XContentParser.Token token; - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { String currentFieldName = null; assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); @@ -255,7 +255,7 @@ public void testCopyCurrentStructure() throws Exception { } } assertNotNull(filterBuilder); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(filterBuilder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(filterBuilder))) { assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME)); assertThat(parser.currentName(), equalTo("terms")); diff --git a/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java b/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java index 4d1a93ed68d1e..603031256058f 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java @@ -33,6 +33,7 @@ package org.opensearch.common.xcontent.cbor; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.test.OpenSearchTestCase; @@ -41,7 +42,7 @@ public class CborXContentParserTests extends OpenSearchTestCase { public void testEmptyValue() throws IOException { - BytesReference ref = BytesReference.bytes(XContentFactory.cborBuilder().startObject().field("field", "").endObject()); + BytesReference ref = BytesReferenceUtil.bytes(XContentFactory.cborBuilder().startObject().field("field", "").endObject()); for (int i = 0; i < 2; i++) { // Running this part twice triggers the issue. diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java index a82db09e37de1..8a634ebb21c6f 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java @@ -34,6 +34,7 @@ import org.opensearch.common.CheckedFunction; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -1089,7 +1090,7 @@ public void testRawField() throws Exception { .endObject(); Builder sampleWithRaw = builder -> { - BytesReference raw = BytesReference.bytes( + BytesReference raw = BytesReferenceUtil.bytes( XContentBuilder.builder(builder.contentType().xContent()).startObject().field("content", "hello world!").endObject() ); return builder.startObject().field("foo", 0).rawField("raw", raw.streamInput()).endObject(); @@ -1103,7 +1104,7 @@ public void testRawField() throws Exception { testFilter(expectedRawFieldNotFiltered, sampleWithRaw, emptySet(), singleton("f*")); sampleWithRaw = builder -> { - BytesReference raw = BytesReference.bytes( + BytesReference raw = BytesReferenceUtil.bytes( XContentBuilder.builder(builder.contentType().xContent()).startObject().field("content", "hello world!").endObject() ); return builder.startObject().field("foo", 0).rawField("raw", raw.streamInput()).endObject(); diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java b/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java index ed4a48bec32cf..6faee499d74cf 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java @@ -34,6 +34,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -147,7 +148,7 @@ public void testChildBytes() throws IOException { .endObject(); builder.field("field", "value"); builder.endObject().endObject(); - BytesReference input = BytesReference.bytes(builder); + BytesReference input = BytesReferenceUtil.bytes(builder); BytesReference bytes; try ( @@ -217,7 +218,7 @@ public void testEmbeddedObject() throws IOException { CompressedXContent embedded = new CompressedXContent("{\"field\":\"value\"}"); builder.field("bytes", embedded.compressed()); builder.endObject().endObject(); - BytesReference bytes = BytesReference.bytes(builder); + BytesReference bytes = BytesReferenceUtil.bytes(builder); BytesReference inner; try ( diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java b/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java index ca7e04cd70584..c9bd902728c40 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java @@ -33,8 +33,8 @@ package org.opensearch.common.xcontent.support; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -423,7 +423,11 @@ public void testFilterWithEmptyIncludesExcludes() { public void testThatFilterIncludesEmptyObjectWhenUsingIncludes() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("obj").endObject().endObject(); - Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); + Tuple> mapTuple = convertToMap( + BytesReferenceUtil.bytes(builder), + true, + builder.contentType() + ); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[] { "obj" }, Strings.EMPTY_ARRAY); assertThat(mapTuple.v2(), equalTo(filteredSource)); @@ -432,7 +436,11 @@ public void testThatFilterIncludesEmptyObjectWhenUsingIncludes() throws Exceptio public void testThatFilterIncludesEmptyObjectWhenUsingExcludes() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("obj").endObject().endObject(); - Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); + Tuple> mapTuple = convertToMap( + BytesReferenceUtil.bytes(builder), + true, + builder.contentType() + ); Map filteredSource = XContentMapValues.filter( mapTuple.v2(), Strings.EMPTY_ARRAY, @@ -446,7 +454,11 @@ public void testThatFilterIncludesEmptyObjectWhenUsingExcludes() throws Exceptio public void testNotOmittingObjectsWithExcludedProperties() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("obj").field("f1", "v1").endObject().endObject(); - Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); + Tuple> mapTuple = convertToMap( + BytesReferenceUtil.bytes(builder), + true, + builder.contentType() + ); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[] { "obj.f1" }); assertThat(filteredSource.size(), equalTo(1)); @@ -467,7 +479,11 @@ public void testNotOmittingObjectWithNestedExcludedObject() throws Exception { .endObject(); // implicit include - Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); + Tuple> mapTuple = convertToMap( + BytesReferenceUtil.bytes(builder), + true, + builder.contentType() + ); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[] { "*.obj2" }); assertThat(filteredSource.size(), equalTo(1)); @@ -498,7 +514,11 @@ public void testIncludingObjectWithNestedIncludedObject() throws Exception { .endObject() .endObject(); - Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); + Tuple> mapTuple = convertToMap( + BytesReferenceUtil.bytes(builder), + true, + builder.contentType() + ); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[] { "*.obj2" }, Strings.EMPTY_ARRAY); assertThat(filteredSource.size(), equalTo(1)); diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java index ddebc67a08ae3..d5e15a6721de4 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java @@ -34,7 +34,7 @@ import org.junit.Assert; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContent; @@ -94,12 +94,12 @@ static void assertXContentBuilderAsBytes(final XContentBuilder expected, final X XContentParser jsonParser = xContent.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(expected).streamInput() + BytesReferenceUtil.bytes(expected).streamInput() ); XContentParser testParser = xContent.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(actual).streamInput() + BytesReferenceUtil.bytes(actual).streamInput() ); ) { while (true) { diff --git a/server/src/test/java/org/opensearch/index/IndexTests.java b/server/src/test/java/org/opensearch/index/IndexTests.java index 0efe25ca3cbcb..7e35d297ed99f 100644 --- a/server/src/test/java/org/opensearch/index/IndexTests.java +++ b/server/src/test/java/org/opensearch/index/IndexTests.java @@ -34,7 +34,7 @@ import org.opensearch.cluster.ClusterState; import org.opensearch.common.UUIDs; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -71,7 +71,7 @@ public void testXContent() throws IOException { final Index original = new Index(name, uuid); final XContentBuilder builder = JsonXContent.contentBuilder(); original.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { parser.nextToken(); // the beginning of the parser assertThat(Index.fromXContent(parser), equalTo(original)); } diff --git a/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java b/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java index 75a346e444b73..e7062df63e6a5 100644 --- a/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java +++ b/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java @@ -47,6 +47,7 @@ import org.opensearch.common.logging.MockAppender; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexingSlowLog.IndexingSlowLogMessage; @@ -218,7 +219,7 @@ private IndexMetadata createIndexMetadata(SlowLogLevel level, String index, Stri } public void testSlowLogMessageHasJsonFields() throws IOException { - BytesReference source = BytesReference.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); + BytesReference source = BytesReferenceUtil.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); ParsedDocument pd = new ParsedDocument( new NumericDocValuesField("version", 1), SeqNoFieldMapper.SequenceIDFields.emptySeqID(), @@ -246,7 +247,7 @@ public void testSlowLogMessageHasJsonFields() throws IOException { } public void testSlowLogParsedDocumentPrinterSourceToLog() throws IOException { - BytesReference source = BytesReference.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); + BytesReference source = BytesReferenceUtil.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); ParsedDocument pd = new ParsedDocument( new NumericDocValuesField("version", 1), SeqNoFieldMapper.SequenceIDFields.emptySeqID(), diff --git a/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java b/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java index fef7b67da5c34..fd9973088acd9 100644 --- a/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java +++ b/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java @@ -35,8 +35,8 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.BytesRef; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -81,16 +81,16 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(doc), XContentType.JSON)); + ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); BytesRef bytes1 = randomBytes(); doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1.bytes, bytes1.offset, bytes1.length).endObject(); - d = mapper.parse(new SourceToParse("test", "2", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "2", BytesReferenceUtil.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); doc = XContentFactory.jsonBuilder().startObject().endObject(); - d = mapper.parse(new SourceToParse("test", "3", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "3", BytesReferenceUtil.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); // test remove duplicate value @@ -106,7 +106,7 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - d = mapper.parse(new SourceToParse("test", "4", BytesReference.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "4", BytesReferenceUtil.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); IndexFieldData indexFieldData = getForField("field"); diff --git a/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java index 1f99c855ce806..493c95b1c6291 100644 --- a/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java @@ -47,8 +47,8 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.Fuzziness; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.ToXContent; @@ -209,7 +209,7 @@ public void testTypeParsing() throws Exception { XContentBuilder builder = jsonBuilder().startObject(); fieldMapper.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true"))).endObject(); builder.close(); - Map serializedMap = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)).map(); + Map serializedMap = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)).map(); Map configMap = (Map) serializedMap.get("field"); assertThat(configMap.get("analyzer").toString(), is("simple")); assertThat(configMap.get("search_analyzer").toString(), is("standard")); diff --git a/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java index 5fe1a979ef1e7..2652570a3172a 100644 --- a/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java @@ -33,7 +33,7 @@ package org.opensearch.index.mapper; import org.apache.lucene.index.IndexableField; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -85,7 +85,7 @@ public void testCopyToFieldsParsing() throws Exception { stringFieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject(); builder.close(); Map serializedMap; - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { serializedMap = parser.map(); } Map copyTestMap = (Map) serializedMap.get("copy_test"); diff --git a/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java index 374b7ac9a5271..d87216b36d6f1 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java @@ -9,8 +9,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -77,7 +77,7 @@ public void testDeeplyNestedCustomTimestampField() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("event") @@ -97,7 +97,7 @@ public void testDeeplyNestedCustomTimestampField() throws Exception { new SourceToParse( "test", "3", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("event") @@ -126,7 +126,7 @@ private void assertDataStreamFieldMapper(String mapping, String timestampFieldNa new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder().startObject().field(timestampFieldName, "2020-12-06T11:04:05.000Z").endObject() ), XContentType.JSON @@ -144,7 +144,7 @@ private void assertDataStreamFieldMapper(String mapping, String timestampFieldNa new SourceToParse( "test", "2", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder().startObject().field("invalid-field-name", "2020-12-06T11:04:05.000Z").endObject() ), XContentType.JSON @@ -162,7 +162,7 @@ private void assertDataStreamFieldMapper(String mapping, String timestampFieldNa new SourceToParse( "test", "3", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .array(timestampFieldName, "2020-12-06T11:04:05.000Z", "2020-12-07T11:04:05.000Z") diff --git a/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java index 222cdf9f7684c..a4373c45af8ea 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java @@ -34,6 +34,7 @@ import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -359,7 +360,7 @@ public void testDefaultFloatingPointMappings() throws IOException { } private void doTestDefaultFloatingPointMappings(DocumentMapper mapper, XContentBuilder builder) throws IOException { - BytesReference source = BytesReference.bytes( + BytesReference source = BytesReferenceUtil.bytes( builder.startObject() .field("foo", 3.2f) // float .field("bar", 3.2d) // double diff --git a/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java index 639de9d314641..da4a7b8f39af2 100644 --- a/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java @@ -35,8 +35,8 @@ import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -111,7 +111,7 @@ public void testInjectIntoDocDuringParsing() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder().startObject().field("a", "100").startObject("b").field("c", 42).endObject().endObject() ), XContentType.JSON @@ -148,7 +148,7 @@ public void testExplicitEnabled() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); @@ -178,7 +178,7 @@ public void testDisabled() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java b/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java index 54393b10a3c5d..304d5df9ea92b 100644 --- a/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java @@ -9,8 +9,8 @@ import org.apache.lucene.index.LeafReaderContext; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -43,7 +43,7 @@ public void testDocValue() throws Exception { final DocumentMapper mapper = mapperService.documentMapperParser().parse("test", new CompressedXContent(mapping)); XContentBuilder json = XContentFactory.jsonBuilder().startObject().startObject("field").field("foo", "bar").endObject().endObject(); - ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(json), XContentType.JSON)); + ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(json), XContentType.JSON)); writer.addDocument(d.rootDoc()); writer.commit(); diff --git a/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java index 93d0596a9bfb5..80ab4ec52543e 100644 --- a/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java @@ -36,9 +36,9 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -73,7 +73,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_id", "1").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("_id", "1").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java index c4225cb576550..07c2221c15626 100644 --- a/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; @@ -64,7 +64,7 @@ public void testDefaultDisabledIndexMapper() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java index e5c8e822b2f56..506c02f6bcbf7 100644 --- a/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java @@ -35,9 +35,9 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.network.InetAddresses; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -176,6 +176,6 @@ private final SourceToParse source(CheckedConsumer XContentBuilder builder = JsonXContent.contentBuilder().startObject(); build.accept(builder); builder.endObject(); - return new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON); + return new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON); } } diff --git a/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java b/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java index 7e00a463124f1..6ada4acdec0b4 100644 --- a/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java @@ -35,6 +35,7 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.ParseContext.Document; @@ -55,7 +56,7 @@ public void testMergeMultiField() throws Exception { assertTrue(mapperService.fieldType("name").isSearchable()); assertThat(mapperService.fieldType("name.indexed"), nullValue()); - BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); + BytesReference json = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); @@ -108,7 +109,7 @@ public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { assertTrue(mapperService.fieldType("name").isSearchable()); assertThat(mapperService.fieldType("name.indexed"), nullValue()); - BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); + BytesReference json = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); diff --git a/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java b/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java index 01a901b3cd5cb..c8021b7242b3f 100644 --- a/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java @@ -35,9 +35,9 @@ import org.apache.lucene.analysis.TokenStream; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.env.Environment; @@ -124,7 +124,7 @@ private CompressedXContent createMappingSpecifyingNumberOfFields(int numberOfFie mappingBuilder.endObject(); } mappingBuilder.endObject().endObject(); - return new CompressedXContent(BytesReference.bytes(mappingBuilder)); + return new CompressedXContent(BytesReferenceUtil.bytes(mappingBuilder)); } public void testMappingDepthExceedsLimit() throws Throwable { @@ -136,7 +136,7 @@ public void testMappingDepthExceedsLimit() throws Throwable { indexService1.mapperService().merge("type", createMappingSpecifyingNumberOfFields(1), MergeReason.MAPPING_UPDATE); CompressedXContent objectMapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -203,7 +203,7 @@ public void testIndexSortWithNestedFields() throws IOException { assertThat(invalidNestedException.getMessage(), containsString("cannot have nested fields when index sort is activated")); IndexService indexService = createIndex("test", settings, "t", "foo", "type=keyword"); CompressedXContent nestedFieldMapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -226,7 +226,7 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable { MapperService mapperService = indexService.mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -246,7 +246,7 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable { mapperService.merge("type", mapping, MergeReason.MAPPING_UPDATE); CompressedXContent mappingUpdate = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -311,7 +311,7 @@ public void testFieldNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -328,7 +328,7 @@ public void testFieldNameLengthLimit() throws Throwable { mapperService.merge("type", mapping, MergeReason.MAPPING_UPDATE); CompressedXContent mappingUpdate = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -356,7 +356,7 @@ public void testObjectNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -386,7 +386,7 @@ public void testAliasFieldNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -420,7 +420,7 @@ public void testMappingRecoverySkipFieldNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -450,7 +450,7 @@ public void testReloadSearchAnalyzers() throws IOException { MapperService mapperService = createIndex("test_index", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") diff --git a/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java index 7722e7c07d8a9..7a8af30559361 100644 --- a/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java @@ -34,9 +34,9 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -87,7 +87,9 @@ public void testEmptyNested() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").nullField("nested1").endObject()), + BytesReferenceUtil.bytes( + XContentFactory.jsonBuilder().startObject().field("field", "value").nullField("nested1").endObject() + ), XContentType.JSON ) ); @@ -98,7 +100,7 @@ public void testEmptyNested() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested").endArray().endObject() ), XContentType.JSON @@ -134,7 +136,7 @@ public void testSingleNested() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -159,7 +161,7 @@ public void testSingleNested() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -227,7 +229,7 @@ public void testMultiNested() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -321,7 +323,7 @@ public void testMultiObjectAndNested1() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -416,7 +418,7 @@ public void testMultiObjectAndNested2() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -510,7 +512,7 @@ public void testMultiRootAndNested1() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -604,7 +606,7 @@ public void testMultipleLevelsIncludeRoot1() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startArray("nested1") @@ -673,7 +675,7 @@ public void testMultipleLevelsIncludeRoot2() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startArray("nested1") @@ -757,7 +759,7 @@ public void testMultipleLevelsIncludeRootWithMerge() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startArray("nested1") @@ -812,7 +814,7 @@ public void testNestedArrayStrict() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -963,7 +965,7 @@ public void testLimitNestedDocsDefaultSettings() throws Exception { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = new SourceToParse("test1", "1", BytesReference.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "1", BytesReferenceUtil.bytes(docBuilder), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source1)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" @@ -1008,7 +1010,7 @@ public void testLimitNestedDocs() throws Exception { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = new SourceToParse("test1", "1", BytesReference.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "1", BytesReferenceUtil.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -1025,7 +1027,7 @@ public void testLimitNestedDocs() throws Exception { docBuilder2.endArray(); } docBuilder2.endObject(); - SourceToParse source2 = new SourceToParse("test1", "2", BytesReference.bytes(docBuilder2), XContentType.JSON); + SourceToParse source2 = new SourceToParse("test1", "2", BytesReferenceUtil.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" @@ -1077,7 +1079,7 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = new SourceToParse("test1", "1", BytesReference.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "1", BytesReferenceUtil.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -1099,7 +1101,7 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception { } docBuilder2.endObject(); - SourceToParse source2 = new SourceToParse("test1", "2", BytesReference.bytes(docBuilder2), XContentType.JSON); + SourceToParse source2 = new SourceToParse("test1", "2", BytesReferenceUtil.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" diff --git a/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java index 95c21823bfcae..1fc5e8cde1b18 100644 --- a/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -66,7 +66,7 @@ public void testNullValueObject() throws IOException { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder().startObject().startObject("obj1").endObject().field("value1", "test1").endObject() ), XContentType.JSON @@ -79,7 +79,9 @@ public void testNullValueObject() throws IOException { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("obj1").field("value1", "test1").endObject()), + BytesReferenceUtil.bytes( + XContentFactory.jsonBuilder().startObject().nullField("obj1").field("value1", "test1").endObject() + ), XContentType.JSON ) ); @@ -90,7 +92,7 @@ public void testNullValueObject() throws IOException { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("obj1") diff --git a/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java index 92236ad34013b..1cb01a241d6f3 100644 --- a/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -54,7 +54,7 @@ public void testRoutingMapper() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON, "routing_value" ) @@ -75,7 +75,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_routing", "foo").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("_routing", "foo").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java index 6925faa44b556..f1c9525daa7c8 100644 --- a/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java @@ -35,8 +35,8 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.XContentParser; @@ -70,7 +70,7 @@ public void testNoFormat() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); @@ -82,7 +82,7 @@ public void testNoFormat() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes(XContentFactory.smileBuilder().startObject().field("field", "value").endObject()), + BytesReferenceUtil.bytes(XContentFactory.smileBuilder().startObject().field("field", "value").endObject()), XContentType.SMILE ) ); @@ -110,7 +110,7 @@ public void testIncludes() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("path1") @@ -154,7 +154,7 @@ public void testExcludes() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("path1") diff --git a/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java b/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java index 3a608ebe828e1..e4e8666c6aa38 100644 --- a/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java @@ -38,9 +38,9 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.ByteBuffersDirectory; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.lucene.Lucene; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -117,7 +117,7 @@ public void testBytesAndNumericRepresentation() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("field1", 1) diff --git a/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java b/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java index 5b536a5756c95..f385c94151e3f 100644 --- a/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java @@ -33,7 +33,7 @@ package org.opensearch.index.mapper; import org.opensearch.Version; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -85,7 +85,7 @@ public void testMultiFieldWithinMultiField() throws IOException { Mapper.TypeParser typeParser = KeywordFieldMapper.PARSER; - Map fieldNode = XContentHelper.convertToMap(BytesReference.bytes(mapping), true, mapping.contentType()).v2(); + Map fieldNode = XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), true, mapping.contentType()).v2(); MapperService mapperService = mock(MapperService.class); IndexAnalyzers indexAnalyzers = new IndexAnalyzers(defaultAnalyzers(), Collections.emptyMap(), Collections.emptyMap()); diff --git a/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java index cd22f72c8ffbc..0cb3b57201bda 100644 --- a/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java @@ -35,9 +35,9 @@ import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.index.IndexService; @@ -91,7 +91,7 @@ protected void testConflictWhileMergingAndMappingUnchanged(XContentBuilder mappi indexService.mapperService() .merge( MapperService.SINGLE_MAPPING_NAME, - new CompressedXContent(BytesReference.bytes(mappingUpdate)), + new CompressedXContent(BytesReferenceUtil.bytes(mappingUpdate)), MapperService.MergeReason.MAPPING_UPDATE ); fail(); diff --git a/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java b/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java index 44fb838cfc647..6b955bc6a785a 100644 --- a/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java +++ b/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -89,7 +90,7 @@ protected ReindexRequest createTestInstance() { if (randomBoolean()) { try (XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint()) { - BytesReference query = BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); + BytesReference query = BytesReferenceUtil.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); reindexRequest.setRemoteInfo( new RemoteInfo( randomAlphaOfLength(5), @@ -365,7 +366,7 @@ public void testReindexFromRemoteRequestParsing() throws IOException { b.endObject(); } b.endObject(); - request = BytesReference.bytes(b); + request = BytesReferenceUtil.bytes(b); } try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) { ReindexRequest r = ReindexRequest.fromXContent(p); @@ -422,7 +423,7 @@ private ReindexRequest parseRequestWithSourceIndices(Object sourceIndices) throw b.endObject(); } b.endObject(); - request = BytesReference.bytes(b); + request = BytesReferenceUtil.bytes(b); } try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) { return ReindexRequest.fromXContent(p); diff --git a/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java b/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java index 16d5fb9c404b3..f0058cdf5f139 100644 --- a/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java +++ b/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java @@ -33,9 +33,9 @@ package org.opensearch.index.search.geo; import org.opensearch.OpenSearchParseException; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.geo.GeoUtils; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -140,12 +140,12 @@ public void testInvalidPointEmbeddedObject() throws IOException { content.endObject(); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -158,12 +158,12 @@ public void testInvalidPointLatHashMix() throws IOException { content.field("lat", 0).field("geohash", stringEncode(0d, 0d)); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -176,13 +176,13 @@ public void testInvalidPointLonHashMix() throws IOException { content.field("lon", 0).field("geohash", stringEncode(0d, 0d)); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -195,13 +195,13 @@ public void testInvalidField() throws IOException { content.field("lon", 0).field("lat", 0).field("test", 0); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -214,7 +214,7 @@ public void testInvalidGeoHash() throws IOException { content.field("geohash", "!!!!"); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); @@ -227,7 +227,7 @@ private XContentParser objectLatLon(double lat, double lon) throws IOException { content.startObject(); content.field("lat", lat).field("lon", lon); content.endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); parser.nextToken(); return parser; } @@ -235,7 +235,7 @@ private XContentParser objectLatLon(double lat, double lon) throws IOException { private XContentParser arrayLatLon(double lat, double lon) throws IOException { XContentBuilder content = JsonXContent.contentBuilder(); content.startArray().value(lon).value(lat).endArray(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); parser.nextToken(); return parser; } @@ -243,7 +243,7 @@ private XContentParser arrayLatLon(double lat, double lon) throws IOException { private XContentParser stringLatLon(double lat, double lon) throws IOException { XContentBuilder content = JsonXContent.contentBuilder(); content.value(Double.toString(lat) + ", " + Double.toString(lon)); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); parser.nextToken(); return parser; } @@ -251,7 +251,7 @@ private XContentParser stringLatLon(double lat, double lon) throws IOException { private XContentParser geohash(double lat, double lon) throws IOException { XContentBuilder content = JsonXContent.contentBuilder(); content.value(stringEncode(lon, lat)); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); parser.nextToken(); return parser; } diff --git a/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java index 3b4db9e7a5a3c..646b3b7692b48 100644 --- a/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java @@ -36,6 +36,7 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.ByteSizeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -75,7 +76,7 @@ public void testToFromXContent() throws IOException { BlobStoreIndexShardSnapshot.FileInfo info = new BlobStoreIndexShardSnapshot.FileInfo("_foobar", meta, size); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); BlobStoreIndexShardSnapshot.FileInfo.toXContent(info, builder, ToXContent.EMPTY_PARAMS); - byte[] xcontent = BytesReference.toBytes(BytesReference.bytes(shuffleXContent(builder))); + byte[] xcontent = BytesReference.toBytes(BytesReferenceUtil.bytes(shuffleXContent(builder))); final BlobStoreIndexShardSnapshot.FileInfo parsedInfo; try (XContentParser parser = createParser(JsonXContent.jsonXContent, xcontent)) { @@ -134,7 +135,7 @@ public void testInvalidFieldsInFromXContent() throws IOException { builder.field(FileInfo.WRITTEN_BY, Version.LATEST.toString()); builder.field(FileInfo.CHECKSUM, "666"); builder.endObject(); - byte[] xContent = BytesReference.toBytes(BytesReference.bytes(builder)); + byte[] xContent = BytesReference.toBytes(BytesReferenceUtil.bytes(builder)); if (failure == null) { // No failures should read as usual diff --git a/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java b/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java index 1cb6579c0f1f2..20c14a6b92775 100644 --- a/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java +++ b/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java @@ -10,6 +10,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -197,7 +198,7 @@ public void testFromXContentInvalid() throws IOException { } builder.endArray(); builder.endObject(); - byte[] xContent = BytesReference.toBytes(BytesReference.bytes(builder)); + byte[] xContent = BytesReference.toBytes(BytesReferenceUtil.bytes(builder)); if (failure == null) { // No failures should read as usual diff --git a/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java b/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java index 78350b7ab4c04..561970c3766f7 100644 --- a/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java +++ b/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java @@ -36,6 +36,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ContextParser; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -77,7 +78,7 @@ public void testParser() throws IOException { builder, ToXContent.EMPTY_PARAMS ); - bytes = BytesReference.bytes(builder); + bytes = BytesReferenceUtil.bytes(builder); } XContentParser xContentParser = xContentType.xContent() diff --git a/server/src/test/java/org/opensearch/repositories/IndexIdTests.java b/server/src/test/java/org/opensearch/repositories/IndexIdTests.java index 3554f2743698a..c12d315c0a569 100644 --- a/server/src/test/java/org/opensearch/repositories/IndexIdTests.java +++ b/server/src/test/java/org/opensearch/repositories/IndexIdTests.java @@ -33,8 +33,8 @@ package org.opensearch.repositories; import org.opensearch.common.UUIDs; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -82,7 +82,7 @@ public void testXContent() throws IOException { IndexId indexId = new IndexId(randomAlphaOfLength(8), UUIDs.randomBase64UUID()); XContentBuilder builder = JsonXContent.contentBuilder(); indexId.toXContent(builder, ToXContent.EMPTY_PARAMS); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); String name = null; String id = null; diff --git a/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java b/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java index 8d76f4a91837d..5d30e7a3da530 100644 --- a/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java +++ b/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java @@ -35,7 +35,7 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.Version; import org.opensearch.common.UUIDs; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -93,7 +93,7 @@ public void testXContent() throws IOException { RepositoryData repositoryData = generateRandomRepoData(); XContentBuilder builder = JsonXContent.contentBuilder(); repositoryData.snapshotsToXContent(builder, Version.CURRENT); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { long gen = (long) randomIntBetween(0, 500); RepositoryData fromXContent = RepositoryData.snapshotsFromXContent(parser, gen); assertEquals(repositoryData, fromXContent); diff --git a/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java b/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java index 0e58e8ce719f6..cc070ba9c9c38 100644 --- a/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java +++ b/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java @@ -41,8 +41,8 @@ import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.ShardSearchFailure; import org.opensearch.common.ParsingException; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.transport.TransportAddress; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -130,7 +130,7 @@ public void testErrorTrace() throws Exception { String text = response.content().utf8ToString(); assertThat(text, containsString("\"type\":\"unknown_exception\",\"reason\":\"an error occurred reading data\"")); assertThat(text, containsString("{\"type\":\"file_not_found_exception\"")); - assertThat(text, containsString("\"stack_trace\":\"[an error occurred reading data]")); + assertThat(text, containsString("\"stack_trace\":\"OpenSearchException[an error occurred reading data]")); } public void testGuessRootCause() throws IOException { @@ -348,7 +348,7 @@ public void testNoErrorFromXContent() throws IOException { builder.field("status", randomFrom(RestStatus.values()).getStatus()); builder.endObject(); - try (XContentParser parser = createParser(builder.contentType().xContent(), BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(builder.contentType().xContent(), BytesReferenceUtil.bytes(builder))) { BytesRestResponse.errorFromXContent(parser); } } diff --git a/server/src/test/java/org/opensearch/rest/RestControllerTests.java b/server/src/test/java/org/opensearch/rest/RestControllerTests.java index 489419fc24526..a2ca3b092ed4b 100644 --- a/server/src/test/java/org/opensearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/opensearch/rest/RestControllerTests.java @@ -42,6 +42,7 @@ import org.opensearch.common.transport.BoundTransportAddress; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.unit.ByteSizeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentType; @@ -477,7 +478,7 @@ public boolean supportsContentStream() { public void testNonStreamingXContentCausesErrorResponse() throws IOException { FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent( - BytesReference.bytes(YamlXContent.contentBuilder().startObject().endObject()), + BytesReferenceUtil.bytes(YamlXContent.contentBuilder().startObject().endObject()), XContentType.YAML ).withPath("/foo").build(); AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); diff --git a/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java b/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java index b128a3e30166f..243ebc54b47e8 100644 --- a/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.action.main.MainResponse; import org.opensearch.cluster.ClusterName; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.json.JsonXContent; @@ -106,7 +107,7 @@ public void testGetResponse() throws Exception { responseBuilder.prettyPrint().lfAtEnd(); } mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS); - BytesReference xcontentBytes = BytesReference.bytes(responseBuilder); + BytesReference xcontentBytes = BytesReferenceUtil.bytes(responseBuilder); assertEquals(xcontentBytes, response.content()); } } diff --git a/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java index 047fe0f286393..7e60dfec1541d 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java @@ -32,7 +32,7 @@ package org.opensearch.rest.action.admin.indices; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -62,7 +62,7 @@ public void testPrepareTypelessRequest() throws IOException { .endObject() .endObject(); - Map contentAsMap = XContentHelper.convertToMap(BytesReference.bytes(content), true, content.contentType()).v2(); + Map contentAsMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(content), true, content.contentType()).v2(); Map source = RestCreateIndexAction.prepareMappings(contentAsMap); XContentBuilder expectedContent = XContentFactory.jsonBuilder() @@ -85,7 +85,7 @@ public void testPrepareTypelessRequest() throws IOException { .endObject() .endObject(); Map expectedContentAsMap = XContentHelper.convertToMap( - BytesReference.bytes(expectedContent), + BytesReferenceUtil.bytes(expectedContent), true, expectedContent.contentType() ).v2(); @@ -103,7 +103,7 @@ public void testMalformedMappings() throws IOException { .endObject() .endObject(); - Map contentAsMap = XContentHelper.convertToMap(BytesReference.bytes(content), true, content.contentType()).v2(); + Map contentAsMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(content), true, content.contentType()).v2(); Map source = RestCreateIndexAction.prepareMappings(contentAsMap); assertEquals(contentAsMap, source); diff --git a/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java b/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java index 9c139f6de573f..db3e0fc70c64d 100644 --- a/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java +++ b/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java @@ -33,8 +33,8 @@ import org.opensearch.cluster.DiffableUtils; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -57,7 +57,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); expectThrows(IllegalArgumentException.class, () -> ScriptMetadata.fromXContent(parser0)); @@ -74,7 +74,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); expectThrows(IllegalArgumentException.class, () -> ScriptMetadata.fromXContent(parser1)); @@ -96,7 +96,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); expectThrows(IllegalArgumentException.class, () -> ScriptMetadata.fromXContent(parser2)); @@ -113,7 +113,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser3); } @@ -131,12 +131,12 @@ public void testGetScript() throws Exception { .endObject() .endObject(); XContentType xContentType = XContentType.fromMediaType(sourceBuilder.contentType()); - builder.storeScript("source_template", StoredScriptSource.parse(BytesReference.bytes(sourceBuilder), xContentType)); + builder.storeScript("source_template", StoredScriptSource.parse(BytesReferenceUtil.bytes(sourceBuilder), xContentType)); sourceBuilder = XContentFactory.jsonBuilder(); xContentType = XContentType.fromMediaType(sourceBuilder.contentType()); sourceBuilder.startObject().startObject("script").field("lang", "_lang").field("source", "_source").endObject().endObject(); - builder.storeScript("script", StoredScriptSource.parse(BytesReference.bytes(sourceBuilder), xContentType)); + builder.storeScript("script", StoredScriptSource.parse(BytesReferenceUtil.bytes(sourceBuilder), xContentType)); ScriptMetadata scriptMetadata = builder.build(); assertEquals("_source", scriptMetadata.getStoredScript("script").getSource()); @@ -206,7 +206,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertWarnings("empty templates should no longer be used"); @@ -217,7 +217,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertWarnings("empty scripts should no longer be used"); @@ -228,7 +228,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertNoDeprecationWarnings(); @@ -239,7 +239,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertNoDeprecationWarnings(); @@ -275,7 +275,7 @@ public void testOldStyleDropped() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder).streamInput() + BytesReferenceUtil.bytes(builder).streamInput() ); ScriptMetadata smd = ScriptMetadata.fromXContent(parser); assertNull(smd.getStoredScript("painless#test")); @@ -303,7 +303,7 @@ private ScriptMetadata randomScriptMetadata(XContentType sourceContentType, int .endObject(); builder.storeScript( randomAlphaOfLength(i + 1), - StoredScriptSource.parse(BytesReference.bytes(sourceBuilder), XContentType.fromMediaType(sourceBuilder.contentType())) + StoredScriptSource.parse(BytesReferenceUtil.bytes(sourceBuilder), XContentType.fromMediaType(sourceBuilder.contentType())) ); } return builder.build(); diff --git a/server/src/test/java/org/opensearch/script/ScriptServiceTests.java b/server/src/test/java/org/opensearch/script/ScriptServiceTests.java index 0485fc9935f15..7b15ffcd1ad0c 100644 --- a/server/src/test/java/org/opensearch/script/ScriptServiceTests.java +++ b/server/src/test/java/org/opensearch/script/ScriptServiceTests.java @@ -43,6 +43,7 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.env.Environment; @@ -365,7 +366,7 @@ public void testContextCacheStats() throws IOException { } public void testStoreScript() throws Exception { - BytesReference script = BytesReference.bytes( + BytesReference script = BytesReferenceUtil.bytes( XContentFactory.jsonBuilder() .startObject() .field("script") diff --git a/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java b/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java index 1f33a51c9253c..2309bbae31f67 100644 --- a/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java +++ b/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java @@ -33,8 +33,8 @@ package org.opensearch.script; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable.Reader; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -66,7 +66,7 @@ protected StoredScriptSource createTestInstance() { if (randomBoolean()) { options.put(Script.CONTENT_TYPE_OPTION, xContentType.mediaType()); } - return StoredScriptSource.parse(BytesReference.bytes(template), xContentType); + return StoredScriptSource.parse(BytesReferenceUtil.bytes(template), xContentType); } catch (IOException e) { throw new AssertionError("Failed to create test instance", e); } diff --git a/server/src/test/java/org/opensearch/script/StoredScriptTests.java b/server/src/test/java/org/opensearch/script/StoredScriptTests.java index a943920dc1451..8dfdeff29b8f4 100644 --- a/server/src/test/java/org/opensearch/script/StoredScriptTests.java +++ b/server/src/test/java/org/opensearch/script/StoredScriptTests.java @@ -35,8 +35,8 @@ import org.opensearch.ResourceNotFoundException; import org.opensearch.common.ParsingException; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; @@ -76,7 +76,7 @@ public void testSourceParsing() throws Exception { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().startObject("script").field("lang", "lang").field("source", "code").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -98,7 +98,7 @@ public void testSourceParsing() throws Exception { code = Strings.toString(cb.startObject().field("query", "code").endObject()); } - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource( "mustache", code, @@ -112,7 +112,7 @@ public void testSourceParsing() throws Exception { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "lang").field("source", "code").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -122,7 +122,7 @@ public void testSourceParsing() throws Exception { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -142,7 +142,7 @@ public void testSourceParsing() throws Exception { .endObject() .endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -169,7 +169,7 @@ public void testSourceParsing() throws Exception { code = Strings.toString(cb.startObject().field("query", "code").endObject()); } - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource( "lang", code, @@ -187,7 +187,7 @@ public void testSourceParsingErrors() throws Exception { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, - () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) ); assertThat(iae.getMessage(), equalTo("must specify lang for stored script")); } @@ -198,7 +198,7 @@ public void testSourceParsingErrors() throws Exception { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, - () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) ); assertThat(iae.getMessage(), equalTo("must specify source for stored script")); } @@ -218,7 +218,7 @@ public void testSourceParsingErrors() throws Exception { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, - () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) ); assertThat(iae.getMessage(), equalTo("illegal compiler options [{option=option}] specified")); } @@ -228,7 +228,7 @@ public void testSourceParsingErrors() throws Exception { builder.startObject().field("template", "code").endObject(); ParsingException pEx = expectThrows( ParsingException.class, - () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) ); assertThat( pEx.getMessage(), @@ -241,7 +241,7 @@ public void testEmptyTemplateDeprecations() throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource(Script.DEFAULT_TEMPLATE_LANG, "", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -251,7 +251,7 @@ public void testEmptyTemplateDeprecations() throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "mustache").field("source", "").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource(Script.DEFAULT_TEMPLATE_LANG, "", Collections.emptyMap()); assertThat(parsed, equalTo(source)); diff --git a/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java b/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java index e94b8ccf83c1f..334b6cf0c3f05 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java @@ -34,6 +34,7 @@ import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContent; @@ -277,7 +278,7 @@ public void testParsingExceptionOnUnknownAggregation() throws IOException { builder.endObject(); } builder.endObject(); - BytesReference originalBytes = BytesReference.bytes(builder); + BytesReference originalBytes = BytesReferenceUtil.bytes(builder); try (XContentParser parser = createParser(builder.contentType().xContent(), originalBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); ParsingException ex = expectThrows(ParsingException.class, () -> Aggregations.fromXContent(parser)); diff --git a/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java b/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java index 6e83739ac8771..f2c2ec4519558 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -249,7 +250,7 @@ public void testRewriteAggregation() throws Exception { builder.endObject(); } builder.endObject(); - bytesReference = BytesReference.bytes(builder); + bytesReference = BytesReferenceUtil.bytes(builder); } FilterAggregationBuilder filterAggBuilder = new FilterAggregationBuilder("titles", new WrapperQueryBuilder(bytesReference)); BucketScriptPipelineAggregationBuilder pipelineAgg = new BucketScriptPipelineAggregationBuilder("const", new Script("1")); diff --git a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java index 3d62f3a93e70b..d3f96451d40cc 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -100,7 +101,7 @@ public void testXContentRoundTrip() throws Exception { orig.toXContent(out, ToXContent.EMPTY_PARAMS); out.endObject(); - try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReference.bytes(out))) { + try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(out))) { XContentParser.Token token = in.currentToken(); assertNull(token); @@ -110,7 +111,7 @@ public void testXContentRoundTrip() throws Exception { DoubleBounds read = DoubleBounds.PARSER.apply(in, null); assertEquals(orig, read); } catch (Exception e) { - throw new Exception("Error parsing [" + BytesReference.bytes(out).utf8ToString() + "]", e); + throw new Exception("Error parsing [" + BytesReferenceUtil.bytes(out).utf8ToString() + "]", e); } } } diff --git a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java index e927488edd920..c71e3941501d8 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java @@ -40,6 +40,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.time.DateFormatter; import org.opensearch.common.util.BigArrays; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -198,7 +199,7 @@ public void testXContentRoundTrip() throws Exception { orig.toXContent(out, ToXContent.EMPTY_PARAMS); out.endObject(); - try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReference.bytes(out))) { + try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(out))) { XContentParser.Token token = in.currentToken(); assertNull(token); @@ -208,7 +209,7 @@ public void testXContentRoundTrip() throws Exception { LongBounds read = LongBounds.PARSER.apply(in, null); assertEquals(orig, read); } catch (Exception e) { - throw new Exception("Error parsing [" + BytesReference.bytes(out).utf8ToString() + "]", e); + throw new Exception("Error parsing [" + BytesReferenceUtil.bytes(out).utf8ToString() + "]", e); } } } diff --git a/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java b/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java index 2608c2dee0a23..d59dd760d22b6 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java @@ -41,10 +41,10 @@ import org.apache.lucene.search.TopFieldDocs; import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.BytesRef; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.common.document.DocumentField; import org.opensearch.common.lucene.search.TopDocsAndMaxScore; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -327,8 +327,8 @@ private static void assertEqualsWithErrorMessageFromXCont expectedJson.endObject(); NotEqualMessageBuilder message = new NotEqualMessageBuilder(); message.compareMaps( - XContentHelper.convertToMap(BytesReference.bytes(actualJson), false).v2(), - XContentHelper.convertToMap(BytesReference.bytes(expectedJson), false).v2() + XContentHelper.convertToMap(BytesReferenceUtil.bytes(actualJson), false).v2(), + XContentHelper.convertToMap(BytesReferenceUtil.bytes(expectedJson), false).v2() ); throw new AssertionError("Didn't match expected value:\n" + message); } catch (IOException e) { diff --git a/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java b/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java index 09c4fbc1ba251..9c9e71f3367ae 100644 --- a/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java +++ b/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java @@ -39,6 +39,7 @@ import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -427,7 +428,7 @@ public void testToXContent() throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); XContentBuilder builder = XContentFactory.contentBuilder(xContentType); searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - BytesReference source = BytesReference.bytes(builder); + BytesReference source = BytesReferenceUtil.bytes(builder); Map sourceAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); assertEquals(0, sourceAsMap.size()); } @@ -436,7 +437,7 @@ public void testToXContent() throws IOException { searchSourceBuilder.query(RandomQueryBuilder.createQuery(random())); XContentBuilder builder = XContentFactory.contentBuilder(xContentType); searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - BytesReference source = BytesReference.bytes(builder); + BytesReference source = BytesReferenceUtil.bytes(builder); Map sourceAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); assertEquals(1, sourceAsMap.size()); assertEquals("query", sourceAsMap.keySet().iterator().next()); @@ -450,7 +451,7 @@ public void testToXContentWithPointInTime() throws IOException { searchSourceBuilder.pointInTimeBuilder(new PointInTimeBuilder("id").setKeepAlive(keepAlive)); XContentBuilder builder = XContentFactory.contentBuilder(xContentType); searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - BytesReference bytes = BytesReference.bytes(builder); + BytesReference bytes = BytesReferenceUtil.bytes(builder); Map sourceAsMap = XContentHelper.convertToMap(bytes, false, xContentType).v2(); assertEquals(1, sourceAsMap.size()); @SuppressWarnings("unchecked") diff --git a/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java b/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java index 7356e64ed329b..ab9c9a748ed04 100644 --- a/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java +++ b/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java @@ -34,7 +34,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.memory.MemoryIndex; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.XContentBuilder; @@ -196,7 +196,7 @@ private HitContext hitExecuteMultiple( MemoryIndex index = new MemoryIndex(); LeafReaderContext leafReaderContext = index.createSearcher().getIndexReader().leaves().get(0); HitContext hitContext = new HitContext(searchHit, leafReaderContext, 1, new SourceLookup()); - hitContext.sourceLookup().setSource(source == null ? null : BytesReference.bytes(source)); + hitContext.sourceLookup().setSource(source == null ? null : BytesReferenceUtil.bytes(source)); FetchSourcePhase phase = new FetchSourcePhase(); FetchSubPhaseProcessor processor = phase.getProcessor(fetchContext); diff --git a/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java b/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java index f6d5789c1d503..d44a17033b328 100644 --- a/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java +++ b/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java @@ -34,9 +34,9 @@ import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.document.DocumentField; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.index.IndexService; @@ -446,7 +446,7 @@ private static Map fetchFields(MapperService mapperServic throws IOException { SourceLookup sourceLookup = new SourceLookup(); - sourceLookup.setSource(BytesReference.bytes(source)); + sourceLookup.setSource(BytesReferenceUtil.bytes(source)); FieldFetcher fieldFetcher = FieldFetcher.create(createQueryShardContext(mapperService), null, fields); return fieldFetcher.fetch(sourceLookup, Set.of()); diff --git a/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java b/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java index ca4cb7291b862..99408af0a01b2 100644 --- a/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java +++ b/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java @@ -37,11 +37,11 @@ import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.search.SortedSetSortField; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.text.Text; import org.opensearch.common.util.BigArrays; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; @@ -158,7 +158,7 @@ private SearchAfterBuilder randomJsonSearchFromBuilder() throws IOException { } jsonBuilder.endArray(); jsonBuilder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(jsonBuilder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(jsonBuilder))) { parser.nextToken(); parser.nextToken(); parser.nextToken(); diff --git a/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java b/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java index 636593f9a7d80..873050492291d 100644 --- a/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java @@ -33,6 +33,7 @@ package org.opensearch.search.suggest; import org.opensearch.Version; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesReference; @@ -234,7 +235,7 @@ public void testParsingExceptionOnUnknownSuggestion() throws IOException { builder.endArray(); } builder.endObject(); - BytesReference originalBytes = BytesReference.bytes(builder); + BytesReference originalBytes = BytesReferenceUtil.bytes(builder); try (XContentParser parser = createParser(builder.contentType().xContent(), originalBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); ParsingException ex = expectThrows(ParsingException.class, () -> Suggest.fromXContent(parser)); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java index 248c5280ae54c..89f92f81a379e 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java @@ -42,9 +42,9 @@ import org.apache.lucene.search.suggest.document.ContextSuggestField; import org.apache.lucene.util.BytesRef; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParseException; import org.opensearch.core.xcontent.XContentParser; @@ -99,7 +99,7 @@ public void testIndexingWithNoContexts() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -149,7 +149,7 @@ public void testIndexingWithSimpleContexts() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -194,7 +194,7 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -239,7 +239,7 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -293,7 +293,7 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { Exception e = expectThrows( MapperParsingException.class, - () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)) + () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON)) ); assertEquals( "contexts must be a string, number or boolean or a list of string, number or boolean, but was [VALUE_NULL]", @@ -326,7 +326,7 @@ public void testIndexingWithContextList() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -369,7 +369,7 @@ public void testIndexingWithMixedTypeContextList() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -419,7 +419,7 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { Exception e = expectThrows( MapperParsingException.class, - () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)) + () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON)) ); assertEquals("context array must have string, number or boolean values, but was [VALUE_NULL]", e.getCause().getMessage()); } @@ -462,7 +462,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = defaultMapper.parse( - new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON) + new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON) ); IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name()); assertContextSuggestFields(fields, 3); @@ -470,7 +470,7 @@ public void testIndexingWithMultipleContexts() throws Exception { public void testQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().value("context1"); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -482,7 +482,7 @@ public void testQueryContextParsingBasic() throws Exception { public void testBooleanQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().value(true); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -494,7 +494,7 @@ public void testBooleanQueryContextParsingBasic() throws Exception { public void testNumberQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().value(10); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -506,7 +506,7 @@ public void testNumberQueryContextParsingBasic() throws Exception { public void testNULLQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().nullValue(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -516,7 +516,7 @@ public void testNULLQueryContextParsingBasic() throws Exception { public void testQueryContextParsingArray() throws Exception { XContentBuilder builder = jsonBuilder().startArray().value("context1").value("context2").endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(2)); @@ -531,7 +531,7 @@ public void testQueryContextParsingArray() throws Exception { public void testQueryContextParsingMixedTypeValuesArray() throws Exception { XContentBuilder builder = jsonBuilder().startArray().value("context1").value("context2").value(true).value(10).endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(4)); @@ -558,7 +558,7 @@ public void testQueryContextParsingMixedTypeValuesArrayHavingNULL() throws Excep .value(10) .nullValue() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -572,7 +572,7 @@ public void testQueryContextParsingObject() throws Exception { .field("boost", 10) .field("prefix", true) .endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -584,7 +584,7 @@ public void testQueryContextParsingObject() throws Exception { public void testQueryContextParsingObjectHavingBoolean() throws Exception { XContentBuilder builder = jsonBuilder().startObject().field("context", false).field("boost", 10).field("prefix", true).endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -596,7 +596,7 @@ public void testQueryContextParsingObjectHavingBoolean() throws Exception { public void testQueryContextParsingObjectHavingNumber() throws Exception { XContentBuilder builder = jsonBuilder().startObject().field("context", 333).field("boost", 10).field("prefix", true).endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -608,7 +608,7 @@ public void testQueryContextParsingObjectHavingNumber() throws Exception { public void testQueryContextParsingObjectHavingNULL() throws Exception { XContentBuilder builder = jsonBuilder().startObject().nullField("context").field("boost", 10).field("prefix", true).endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); Exception e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -629,7 +629,7 @@ public void testQueryContextParsingObjectArray() throws Exception { .field("prefix", false) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(2)); @@ -665,7 +665,7 @@ public void testQueryContextParsingMixedTypeObjectArray() throws Exception { .field("prefix", false) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(4)); @@ -712,7 +712,7 @@ public void testQueryContextParsingMixedTypeObjectArrayHavingNULL() throws Excep .field("prefix", false) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -735,7 +735,7 @@ public void testQueryContextParsingMixed() throws Exception { .field("prefix", true) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(4)); @@ -770,7 +770,7 @@ public void testQueryContextParsingMixedHavingNULL() throws Exception { .endObject() .nullValue() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java index fb6cce3f8e9ab..7823a74a398d5 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java @@ -34,8 +34,8 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.OpenSearchParseException; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -84,7 +84,7 @@ public void testIndexingWithNoContexts() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -131,7 +131,7 @@ public void testIndexingWithSimpleContexts() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -176,7 +176,7 @@ public void testIndexingWithContextList() throws Exception { new SourceToParse( "test", "1", - BytesReference.bytes( + BytesReferenceUtil.bytes( jsonBuilder().startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -237,7 +237,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = mapperService.documentMapper() - .parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)); + .parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -308,7 +308,7 @@ public void testMissingGeoField() throws Exception { public void testParsingQueryContextBasic() throws Exception { XContentBuilder builder = jsonBuilder().value("ezs42e44yx96"); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 8)); @@ -324,7 +324,7 @@ public void testParsingQueryContextBasic() throws Exception { public void testParsingQueryContextGeoPoint() throws Exception { XContentBuilder builder = jsonBuilder().startObject().field("lat", 23.654242).field("lon", 90.047153).endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 8)); @@ -347,7 +347,7 @@ public void testParsingQueryContextObject() throws Exception { .field("boost", 10) .array("neighbours", 1, 2, 3) .endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8)); @@ -385,7 +385,7 @@ public void testParsingQueryContextObjectArray() throws Exception { .array("neighbours", 5) .endObject() .endArray(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 1 + 8)); @@ -428,7 +428,7 @@ public void testParsingQueryContextMixed() throws Exception { .field("lon", 92.112583) .endObject() .endArray(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8)); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java index 377601c5ed435..7deea5a2e66e6 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java @@ -32,8 +32,8 @@ package org.opensearch.search.suggest.completion; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -133,7 +133,7 @@ public void testStringPrecision() throws IOException { builder.array("neighbours", 1, 2); } builder.endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); parser.nextToken(); GeoQueryContext queryContext = fromXContent(parser); assertEquals(10, queryContext.getBoost()); @@ -148,7 +148,7 @@ public void testStringPrecision() throws IOException { builder.array("neighbours", "4km", "10km"); } builder.endObject(); - parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); + parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); parser.nextToken(); queryContext = fromXContent(parser); assertEquals(10, queryContext.getBoost()); diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java index b18aa6c53c107..fcca5450152a0 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java @@ -36,6 +36,7 @@ import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; import org.opensearch.action.support.IndicesOptions; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.test.OpenSearchTestCase; @@ -94,7 +95,7 @@ public void testRestoreSnapshotRequestParsing() throws IOException { builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable()); } - BytesReference bytes = BytesReference.bytes(builder.endObject()); + BytesReference bytes = BytesReferenceUtil.bytes(builder.endObject()); request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2()); @@ -160,7 +161,7 @@ public void testCreateSnapshotRequestParsing() throws IOException { builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable()); } - BytesReference bytes = BytesReference.bytes(builder.endObject()); + BytesReference bytes = BytesReferenceUtil.bytes(builder.endObject()); request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2()); diff --git a/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java b/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java index 5da0727d23fed..1369e57b71de5 100644 --- a/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java +++ b/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java @@ -32,7 +32,7 @@ package org.opensearch.tasks; -import org.opensearch.OpenSearchException; +import org.opensearch.BaseOpenSearchException; import org.opensearch.action.FailedNodeException; import org.opensearch.action.TaskOperationFailure; import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse; @@ -158,15 +158,15 @@ protected void assertEqualInstances(ListTasksResponse expectedInstance, ListTask assertOnTaskFailures(newInstance.getTaskFailures(), expectedInstance.getTaskFailures()); } - protected static void assertOnNodeFailures(List nodeFailures, List expectedFailures) { + protected static void assertOnNodeFailures(List nodeFailures, List expectedFailures) { assertThat(nodeFailures.size(), equalTo(expectedFailures.size())); for (int i = 0; i < nodeFailures.size(); i++) { - OpenSearchException newException = nodeFailures.get(i); - OpenSearchException expectedException = expectedFailures.get(i); + BaseOpenSearchException newException = nodeFailures.get(i); + BaseOpenSearchException expectedException = expectedFailures.get(i); assertThat(newException.getMetadata("opensearch.node_id").get(0), equalTo(((FailedNodeException) expectedException).nodeId())); assertThat(newException.getMessage(), equalTo("OpenSearch exception [type=failed_node_exception, reason=error message]")); - assertThat(newException.getCause(), instanceOf(OpenSearchException.class)); - OpenSearchException cause = (OpenSearchException) newException.getCause(); + assertThat(newException.getCause(), instanceOf(BaseOpenSearchException.class)); + BaseOpenSearchException cause = (BaseOpenSearchException) newException.getCause(); assertThat(cause.getMessage(), equalTo("OpenSearch exception [type=connect_exception, reason=null]")); } } @@ -179,8 +179,8 @@ protected static void assertOnTaskFailures(List taskFailur assertThat(newFailure.getNodeId(), equalTo(expectedFailure.getNodeId())); assertThat(newFailure.getTaskId(), equalTo(expectedFailure.getTaskId())); assertThat(newFailure.getStatus(), equalTo(expectedFailure.getStatus())); - assertThat(newFailure.getCause(), instanceOf(OpenSearchException.class)); - OpenSearchException cause = (OpenSearchException) newFailure.getCause(); + assertThat(newFailure.getCause(), instanceOf(BaseOpenSearchException.class)); + BaseOpenSearchException cause = (BaseOpenSearchException) newFailure.getCause(); assertThat(cause.getMessage(), equalTo("OpenSearch exception [type=illegal_state_exception, reason=null]")); } } diff --git a/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java b/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java index 0ba8ea13cc71c..1a99ac0ee947e 100644 --- a/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java +++ b/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java @@ -33,9 +33,9 @@ package org.opensearch.tasks; import org.opensearch.client.Requests; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.test.AbstractSerializingTestCase; @@ -348,7 +348,7 @@ private static RawTaskStatus randomRawTaskStatus() { builder.field(randomAlphaOfLength(5), randomAlphaOfLength(5)); } builder.endObject(); - return new RawTaskStatus(BytesReference.bytes(builder)); + return new RawTaskStatus(BytesReferenceUtil.bytes(builder)); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java b/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java index f268b80edb44c..ccf8721288969 100644 --- a/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java +++ b/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java @@ -32,12 +32,12 @@ package org.opensearch.threadpool; import org.opensearch.Version; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.SizeValue; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -98,7 +98,7 @@ public void testThatToXContentWritesOutUnboundedCorrectly() throws Exception { info.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - Map map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map map = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); assertThat(map, hasKey("foo")); map = (Map) map.get("foo"); assertThat(map, hasKey("queue_size")); @@ -126,7 +126,7 @@ public void testThatToXContentWritesInteger() throws Exception { info.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - Map map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + Map map = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); assertThat(map, hasKey("foo")); map = (Map) map.get("foo"); assertThat(map, hasKey("queue_size")); diff --git a/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java b/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java index 9370a2a211725..8c1936922b718 100644 --- a/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java @@ -82,6 +82,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.BigArrays; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -450,7 +451,7 @@ public static CheckedBiFunction ne source.endObject(); } source.endObject(); - return nestedMapper.parse(new SourceToParse("test", docId, BytesReference.bytes(source), XContentType.JSON)); + return nestedMapper.parse(new SourceToParse("test", docId, BytesReferenceUtil.bytes(source), XContentType.JSON)); }; } diff --git a/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java b/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java index 30cbe5dcc6091..58e3812279a95 100644 --- a/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java @@ -41,9 +41,9 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -185,7 +185,7 @@ protected final SourceToParse source(CheckedConsumer buildFields) throws IOException { diff --git a/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java b/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java index 420cb5f86e95f..3654753ccc999 100644 --- a/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java @@ -45,7 +45,7 @@ import org.opensearch.common.CheckedConsumer; import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -235,14 +235,14 @@ public void testMeta() throws IOException { }); MapperService mapperService = createMapperService(mapping); assertEquals( - XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(), + XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), false, mapping.contentType()).v2(), XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2() ); mapping = fieldMapping(this::metaMapping); merge(mapperService, mapping); assertEquals( - XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(), + XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), false, mapping.contentType()).v2(), XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2() ); @@ -252,7 +252,7 @@ public void testMeta() throws IOException { }); merge(mapperService, mapping); assertEquals( - XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(), + XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), false, mapping.contentType()).v2(), XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2() ); } diff --git a/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java b/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java index 9dec1f2ba739c..2cabcb5420361 100644 --- a/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java +++ b/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java @@ -35,9 +35,9 @@ import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchType; import org.opensearch.action.support.IndicesOptions; -import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.text.Text; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.FeatureFlags; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -358,7 +358,7 @@ public static SearchSourceBuilder randomSearchSourceBuilder( .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(jsonBuilder).streamInput() + BytesReferenceUtil.bytes(jsonBuilder).streamInput() ); parser.nextToken(); parser.nextToken(); diff --git a/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java b/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java index 9933297aa1c96..ad3fcaf23c8e7 100644 --- a/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -56,6 +56,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -428,7 +429,9 @@ protected String initWithSnapshotVersion(String repoName, Path repoPath, Version ); Files.write( repoPath.resolve(BlobStoreRepository.INDEX_FILE_PREFIX + repositoryData.getGenId()), - BytesReference.toBytes(BytesReference.bytes(downgradedRepoData.snapshotsToXContent(XContentFactory.jsonBuilder(), version))), + BytesReference.toBytes( + BytesReferenceUtil.bytes(downgradedRepoData.snapshotsToXContent(XContentFactory.jsonBuilder(), version)) + ), StandardOpenOption.TRUNCATE_EXISTING ); return oldVersionSnapshot; diff --git a/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java b/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java index d2dfa4ef628e5..ee3edf855a2c1 100644 --- a/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java @@ -36,6 +36,7 @@ import org.opensearch.common.CheckedBiFunction; import org.opensearch.common.CheckedFunction; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContent; @@ -65,7 +66,7 @@ public static XContentTester xContentTester( return new XContentTester<>(createParser, x -> instanceSupplier.get(), (testInstance, xContentType) -> { try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { toXContent.accept(testInstance, builder); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } }, fromXContent); } @@ -306,7 +307,7 @@ static BytesReference insertRandomFieldsAndShuffle( withRandomFields = xContent; } XContentParser parserWithRandonFields = createParserFunction.apply(XContentFactory.xContent(xContentType), withRandomFields); - return BytesReference.bytes(shuffleXContent(parserWithRandonFields, false, shuffleFieldsExceptions)); + return BytesReferenceUtil.bytes(shuffleXContent(parserWithRandonFields, false, shuffleFieldsExceptions)); } } diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java index 4474aae1f0631..9ad2ddac203dc 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java @@ -109,6 +109,7 @@ import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -1202,13 +1203,13 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); metadataWithoutIndices.toXContent(builder, serializationFormatParams); builder.endObject(); - final BytesReference originalBytes = BytesReference.bytes(builder); + final BytesReference originalBytes = BytesReferenceUtil.bytes(builder); XContentBuilder compareBuilder = SmileXContent.contentBuilder(); compareBuilder.startObject(); metadataWithoutIndices.toXContent(compareBuilder, compareFormatParams); compareBuilder.endObject(); - final BytesReference compareOriginalBytes = BytesReference.bytes(compareBuilder); + final BytesReference compareOriginalBytes = BytesReferenceUtil.bytes(compareBuilder); final Metadata loadedMetadata; try ( @@ -1224,7 +1225,7 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); loadedMetadata.toXContent(builder, compareFormatParams); builder.endObject(); - final BytesReference parsedBytes = BytesReference.bytes(builder); + final BytesReference parsedBytes = BytesReferenceUtil.bytes(builder); assertNull( "cluster state XContent serialization does not match, expected " @@ -1243,13 +1244,13 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); indexMetadata.toXContent(builder, serializationFormatParams); builder.endObject(); - final BytesReference originalBytes = BytesReference.bytes(builder); + final BytesReference originalBytes = BytesReferenceUtil.bytes(builder); XContentBuilder compareBuilder = SmileXContent.contentBuilder(); compareBuilder.startObject(); indexMetadata.toXContent(compareBuilder, compareFormatParams); compareBuilder.endObject(); - final BytesReference compareOriginalBytes = BytesReference.bytes(compareBuilder); + final BytesReference compareOriginalBytes = BytesReferenceUtil.bytes(compareBuilder); final IndexMetadata loadedIndexMetadata; try ( @@ -1265,7 +1266,7 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); loadedIndexMetadata.toXContent(builder, compareFormatParams); builder.endObject(); - final BytesReference parsedBytes = BytesReference.bytes(builder); + final BytesReference parsedBytes = BytesReferenceUtil.bytes(builder); assertNull( "cluster state XContent serialization does not match, expected " diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java index 7722b59313b5f..895bc8b88139a 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java @@ -90,6 +90,7 @@ import org.opensearch.common.time.DateUtils; import org.opensearch.common.time.FormatNames; import org.opensearch.common.transport.TransportAddress; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.MockBigArrays; import org.opensearch.common.util.MockPageCacheRecycler; import org.opensearch.common.util.concurrent.ThreadContext; @@ -1286,7 +1287,7 @@ protected final BytesReference toShuffledXContent( BytesReference bytes = XContentHelper.toXContent(toXContent, xContentType, params, humanReadable); try (XContentParser parser = createParser(xContentType.xContent(), bytes)) { try (XContentBuilder builder = shuffleXContent(parser, rarely(), exceptFieldNames)) { - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } } @@ -1306,7 +1307,7 @@ protected final BytesReference toShuffledXContent( BytesReference bytes = XContentHelper.toXContent(toXContent, mediaType, params, humanReadable); try (XContentParser parser = createParser(mediaType.xContent(), bytes)) { try (XContentBuilder builder = shuffleXContent(parser, rarely(), exceptFieldNames)) { - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } } @@ -1463,7 +1464,7 @@ protected static T copyInstance( * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContentBuilder builder) throws IOException { - return createParser(builder.contentType().xContent(), BytesReference.bytes(builder)); + return createParser(builder.contentType().xContent(), BytesReferenceUtil.bytes(builder)); } /** diff --git a/test/framework/src/main/java/org/opensearch/test/RandomObjects.java b/test/framework/src/main/java/org/opensearch/test/RandomObjects.java index 6405aa5ff5c95..b4032190cdcd1 100644 --- a/test/framework/src/main/java/org/opensearch/test/RandomObjects.java +++ b/test/framework/src/main/java/org/opensearch/test/RandomObjects.java @@ -47,6 +47,7 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -209,7 +210,7 @@ public static BytesReference randomSource(Random random, XContentType xContentTy builder.startObject(); addFields(random, builder, minNumFields, 0); builder.endObject(); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java b/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java index 3f8bfe8e9e935..7ebfeb629b3d1 100644 --- a/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java +++ b/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java @@ -33,6 +33,7 @@ package org.opensearch.test; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -71,13 +72,13 @@ public static Map convertToMap(ToXContent part) throws IOExcepti builder.startObject(); part.toXContent(builder, EMPTY_PARAMS); builder.endObject(); - return XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); + return XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); } public static BytesReference convertToXContent(Map map, XContentType xContentType) throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType)) { builder.map(map); - return BytesReference.bytes(builder); + return BytesReferenceUtil.bytes(builder); } } @@ -241,7 +242,7 @@ public static BytesReference insertRandomFields( } } }; - return BytesReference.bytes( + return BytesReferenceUtil.bytes( XContentTestUtils.insertIntoXContent( contentType.xContent(), xContent, diff --git a/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java b/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java index e52a6b48e219d..0b1e119494a77 100644 --- a/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java +++ b/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java @@ -34,6 +34,7 @@ import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TotalHits; +import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionFuture; @@ -626,7 +627,7 @@ public static void assertFutureThrows( } if (status != null) { - assertThat(extraInfo, ExceptionsHelper.status(expected), equalTo(status)); + assertThat(extraInfo, BaseExceptionsHelper.status(expected), equalTo(status)); } } @@ -647,7 +648,7 @@ public static void assertFutureThrows(ActionFuture future, RestStatus status, extraInfo += "expected a " + status + " status exception to be thrown"; Exception e = expectThrows(Exception.class, future::actionGet); - assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status)); + assertThat(extraInfo, BaseExceptionsHelper.status(e), equalTo(status)); } /** diff --git a/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java b/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java index 6cd03a3cf7256..0dbf8b2a12147 100644 --- a/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java +++ b/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java @@ -41,7 +41,7 @@ import org.apache.lucene.util.BytesRef; import org.opensearch.Version; import org.opensearch.client.NodeSelector; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -185,7 +185,7 @@ private XContentType getContentType(Map headers, XContentType[] private BytesRef bodyAsBytesRef(Map bodyAsMap, XContentType xContentType) throws IOException { Map finalBodyAsMap = stash.replaceStashedValues(bodyAsMap); try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType)) { - return BytesReference.bytes(builder.map(finalBodyAsMap)).toBytesRef(); + return BytesReferenceUtil.bytes(builder.map(finalBodyAsMap)).toBytesRef(); } } diff --git a/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java b/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java index 494f7c906628f..a27e6b3ddb17b 100644 --- a/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java +++ b/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java @@ -35,6 +35,7 @@ import com.carrotsearch.randomizedtesting.RandomizedContext; import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; @@ -58,7 +59,7 @@ public void testInsertRandomFieldsAndShuffle() throws Exception { .runWithPrivateRandomness( 1, () -> AbstractXContentTestCase.insertRandomFieldsAndShuffle( - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), XContentType.JSON, true, new String[] {}, diff --git a/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java b/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java index d430d7f2fbcb3..f070f04557605 100644 --- a/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java +++ b/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java @@ -32,7 +32,7 @@ package org.opensearch.test; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -90,7 +90,7 @@ public void testGetInsertPaths() throws IOException { XContentParser parser = XContentHelper.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), builder.contentType() ) ) { @@ -112,28 +112,28 @@ public void testInsertIntoXContent() throws IOException { builder.endObject(); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), Collections.singletonList(""), () -> "inn.er1", () -> new HashMap<>() ); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), Collections.singletonList(""), () -> "field1", () -> "value1" ); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), Collections.singletonList("inn\\.er1"), () -> "inner2", () -> new HashMap<>() ); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), Collections.singletonList("inn\\.er1"), () -> "field2", () -> "value2" @@ -142,7 +142,7 @@ public void testInsertIntoXContent() throws IOException { XContentParser parser = XContentHelper.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReference.bytes(builder), + BytesReferenceUtil.bytes(builder), builder.contentType() ) ) { @@ -195,7 +195,7 @@ public void testInsertRandomXContent() throws IOException { try ( XContentParser parser = createParser( XContentType.JSON.xContent(), - insertRandomFields(builder.contentType(), BytesReference.bytes(builder), null, random()) + insertRandomFields(builder.contentType(), BytesReferenceUtil.bytes(builder), null, random()) ) ) { resultMap = parser.map(); @@ -213,7 +213,7 @@ public void testInsertRandomXContent() throws IOException { try ( XContentParser parser = createParser( XContentType.JSON.xContent(), - insertRandomFields(builder.contentType(), BytesReference.bytes(builder), pathsToExclude, random()) + insertRandomFields(builder.contentType(), BytesReferenceUtil.bytes(builder), pathsToExclude, random()) ) ) { resultMap = parser.map(); @@ -231,7 +231,7 @@ public void testInsertRandomXContent() throws IOException { try ( XContentParser parser = createParser( XContentType.JSON.xContent(), - insertRandomFields(builder.contentType(), BytesReference.bytes(builder), pathsToExclude, random()) + insertRandomFields(builder.contentType(), BytesReferenceUtil.bytes(builder), pathsToExclude, random()) ) ) { resultMap = parser.map(); diff --git a/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java b/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java index ba4ded7fcf604..c7adb1664388b 100644 --- a/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java +++ b/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java @@ -37,7 +37,7 @@ import org.opensearch.cluster.block.ClusterBlock; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -82,12 +82,16 @@ public void testAssertXContentEquivalent() throws IOException { try ( XContentBuilder copy = JsonXContent.contentBuilder(); - XContentParser parser = createParser(original.contentType().xContent(), BytesReference.bytes(original)) + XContentParser parser = createParser(original.contentType().xContent(), BytesReferenceUtil.bytes(original)) ) { parser.nextToken(); copy.generator().copyCurrentStructure(parser); try (XContentBuilder copyShuffled = shuffleXContent(copy)) { - assertToXContentEquivalent(BytesReference.bytes(original), BytesReference.bytes(copyShuffled), original.contentType()); + assertToXContentEquivalent( + BytesReferenceUtil.bytes(original), + BytesReferenceUtil.bytes(copyShuffled), + original.contentType() + ); } } } @@ -119,7 +123,11 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) + () -> assertToXContentEquivalent( + BytesReferenceUtil.bytes(builder), + BytesReferenceUtil.bytes(otherBuilder), + builder.contentType() + ) ); assertThat(error.getMessage(), containsString("f2: expected [value2] but not found")); } @@ -149,7 +157,11 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) + () -> assertToXContentEquivalent( + BytesReferenceUtil.bytes(builder), + BytesReferenceUtil.bytes(otherBuilder), + builder.contentType() + ) ); assertThat(error.getMessage(), containsString("f2: expected String [value2] but was String [differentValue2]")); } @@ -183,7 +195,11 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) + () -> assertToXContentEquivalent( + BytesReferenceUtil.bytes(builder), + BytesReferenceUtil.bytes(otherBuilder), + builder.contentType() + ) ); assertThat(error.getMessage(), containsString("2: expected String [three] but was String [four]")); } @@ -214,7 +230,11 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) + () -> assertToXContentEquivalent( + BytesReferenceUtil.bytes(builder), + BytesReferenceUtil.bytes(otherBuilder), + builder.contentType() + ) ); assertThat(error.getMessage(), containsString("expected [1] more entries")); } diff --git a/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java b/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java index 2465e48b9afac..773d2f8e7ab8a 100644 --- a/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java +++ b/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java @@ -31,7 +31,7 @@ package org.opensearch.test.rest.yaml; -import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -68,7 +68,7 @@ public void testEvaluateObjectPathEscape() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.field2\\.field3"); assertThat(object, instanceOf(String.class)); @@ -84,7 +84,7 @@ public void testEvaluateObjectPathWithDots() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1..field2"); assertThat(object, instanceOf(String.class)); @@ -106,7 +106,7 @@ public void testEvaluateInteger() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.field2"); assertThat(object, instanceOf(Integer.class)); @@ -122,7 +122,7 @@ public void testEvaluateDouble() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.field2"); assertThat(object, instanceOf(Double.class)); @@ -138,7 +138,7 @@ public void testEvaluateArray() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.array1"); assertThat(object, instanceOf(List.class)); @@ -170,7 +170,7 @@ public void testEvaluateArrayElementObject() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.array1.1.element"); assertThat(object, instanceOf(String.class)); @@ -200,7 +200,7 @@ public void testEvaluateObjectKeys() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate("metadata.templates"); assertThat(object, instanceOf(Map.class)); @@ -232,7 +232,7 @@ public void testEvaluateArbitraryKey() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); { @@ -277,7 +277,7 @@ public void testEvaluateStashInPropertyName() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); try { objectPath.evaluate("field1.$placeholder.element1"); @@ -343,7 +343,7 @@ public void testEvaluateArrayAsRoot() throws Exception { xContentBuilder.endArray(); ObjectPath objectPath = ObjectPath.createFromXContent( XContentFactory.xContent(xContentBuilder.contentType()), - BytesReference.bytes(xContentBuilder) + BytesReferenceUtil.bytes(xContentBuilder) ); Object object = objectPath.evaluate(""); assertThat(object, notNullValue()); diff --git a/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java b/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java index ff862a5ae673e..18514243aa106 100644 --- a/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java +++ b/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java @@ -36,6 +36,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.time.DateFormatter; +import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -132,7 +133,7 @@ public void testShuffleXContentExcludeFields() throws IOException { } } builder.endObject(); - BytesReference bytes = BytesReference.bytes(builder); + BytesReference bytes = BytesReferenceUtil.bytes(builder); final LinkedHashMap initialMap; try (XContentParser parser = createParser(xContentType.xContent(), bytes)) { initialMap = (LinkedHashMap) parser.mapOrdered(); From 9bc0d958ed5f832662472609a219e03399b03ba5 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Tue, 13 Jun 2023 09:25:14 -0500 Subject: [PATCH 2/8] fix javadoc failures Signed-off-by: Nicholas Walter Knize --- .../main/java/org/opensearch/action/package-info.java | 10 ++++++++++ .../org/opensearch/action/support/package-info.java | 10 ++++++++++ .../java/org/opensearch/common/bytes/package-info.java | 10 ++++++++++ .../org/opensearch/common/compress/package-info.java | 10 ++++++++++ .../java/org/opensearch/common/io/package-info.java | 10 ++++++++++ .../org/opensearch/common/io/stream/package-info.java | 10 ++++++++++ .../main/java/org/opensearch/common/package-info.java | 10 ++++++++++ .../org/opensearch/common/settings/package-info.java | 10 ++++++++++ .../java/org/opensearch/common/text/package-info.java | 10 ++++++++++ .../java/org/opensearch/common/util/package-info.java | 10 ++++++++++ .../org/opensearch/common/xcontent/package-info.java | 10 ++++++++++ .../org/opensearch/core/common/io/package-info.java | 10 ++++++++++ .../main/java/org/opensearch/index/package-info.java | 10 ++++++++++ .../java/org/opensearch/index/shard/package-info.java | 10 ++++++++++ .../org/opensearch/index/snapshots/package-info.java | 10 ++++++++++ .../main/java/org/opensearch/rest/package-info.java | 10 ++++++++++ .../org/opensearch/common/util/BytesReferenceUtil.java | 5 +++++ 17 files changed, 165 insertions(+) create mode 100644 libs/core/src/main/java/org/opensearch/action/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/action/support/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/bytes/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/compress/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/io/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/io/stream/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/settings/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/text/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/util/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/common/xcontent/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/index/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/index/shard/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/index/snapshots/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/rest/package-info.java diff --git a/libs/core/src/main/java/org/opensearch/action/package-info.java b/libs/core/src/main/java/org/opensearch/action/package-info.java new file mode 100644 index 0000000000000..a7b89f63a6217 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/action/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Core action module */ +package org.opensearch.action; diff --git a/libs/core/src/main/java/org/opensearch/action/support/package-info.java b/libs/core/src/main/java/org/opensearch/action/support/package-info.java new file mode 100644 index 0000000000000..6665904e2b318 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/action/support/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Support classes for core action module */ +package org.opensearch.action.support; diff --git a/libs/core/src/main/java/org/opensearch/common/bytes/package-info.java b/libs/core/src/main/java/org/opensearch/common/bytes/package-info.java new file mode 100644 index 0000000000000..0644188656496 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/bytes/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core Bytes module */ +package org.opensearch.common.bytes; diff --git a/libs/core/src/main/java/org/opensearch/common/compress/package-info.java b/libs/core/src/main/java/org/opensearch/common/compress/package-info.java new file mode 100644 index 0000000000000..b3b2f2a2ec7ed --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/compress/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core compress module */ +package org.opensearch.common.compress; diff --git a/libs/core/src/main/java/org/opensearch/common/io/package-info.java b/libs/core/src/main/java/org/opensearch/common/io/package-info.java new file mode 100644 index 0000000000000..0d57efe860d09 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/io/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core io module */ +package org.opensearch.common.io; diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/package-info.java b/libs/core/src/main/java/org/opensearch/common/io/stream/package-info.java new file mode 100644 index 0000000000000..c332f90371f60 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Core transport stream classes */ +package org.opensearch.common.io.stream; diff --git a/libs/core/src/main/java/org/opensearch/common/package-info.java b/libs/core/src/main/java/org/opensearch/common/package-info.java new file mode 100644 index 0000000000000..211cde81a3b88 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** common core classes that require third party dependencies */ +package org.opensearch.common; diff --git a/libs/core/src/main/java/org/opensearch/common/settings/package-info.java b/libs/core/src/main/java/org/opensearch/common/settings/package-info.java new file mode 100644 index 0000000000000..10c1d5bab5fc1 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/settings/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core Settings module */ +package org.opensearch.common.settings; diff --git a/libs/core/src/main/java/org/opensearch/common/text/package-info.java b/libs/core/src/main/java/org/opensearch/common/text/package-info.java new file mode 100644 index 0000000000000..d9ce2ebbc9340 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/text/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core text module */ +package org.opensearch.common.text; diff --git a/libs/core/src/main/java/org/opensearch/common/util/package-info.java b/libs/core/src/main/java/org/opensearch/common/util/package-info.java new file mode 100644 index 0000000000000..f106d27c21881 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/util/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core util module */ +package org.opensearch.common.util; diff --git a/libs/core/src/main/java/org/opensearch/common/xcontent/package-info.java b/libs/core/src/main/java/org/opensearch/common/xcontent/package-info.java new file mode 100644 index 0000000000000..c4522c2ae6627 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/xcontent/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Base XContent Core Classes */ +package org.opensearch.common.xcontent; diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/package-info.java b/libs/core/src/main/java/org/opensearch/core/common/io/package-info.java new file mode 100644 index 0000000000000..7f5318f53dd35 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/core/common/io/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core io module */ +package org.opensearch.core.common.io; diff --git a/libs/core/src/main/java/org/opensearch/index/package-info.java b/libs/core/src/main/java/org/opensearch/index/package-info.java new file mode 100644 index 0000000000000..bcb93e8c78856 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/index/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core index module */ +package org.opensearch.index; diff --git a/libs/core/src/main/java/org/opensearch/index/shard/package-info.java b/libs/core/src/main/java/org/opensearch/index/shard/package-info.java new file mode 100644 index 0000000000000..3ae1d95494bd6 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/index/shard/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core index/shard module */ +package org.opensearch.index.shard; diff --git a/libs/core/src/main/java/org/opensearch/index/snapshots/package-info.java b/libs/core/src/main/java/org/opensearch/index/snapshots/package-info.java new file mode 100644 index 0000000000000..7102459987dbf --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/index/snapshots/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core snapshots module */ +package org.opensearch.index.snapshots; diff --git a/libs/core/src/main/java/org/opensearch/rest/package-info.java b/libs/core/src/main/java/org/opensearch/rest/package-info.java new file mode 100644 index 0000000000000..a629540e3858c --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/rest/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Classes for core REST module */ +package org.opensearch.rest; diff --git a/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java b/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java index cd5fd9ede8942..c796ac95b38e5 100644 --- a/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java +++ b/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java @@ -16,6 +16,11 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; +/** + * Server specific utilities for BytesReference objects + * + * @opensearch.internal + */ public class BytesReferenceUtil { /** * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder, From d8790d2f5531eee6267aa3adb8921dbae8302444 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Tue, 13 Jun 2023 19:14:53 -0500 Subject: [PATCH 3/8] remove BaseOpenSearchException in favor of OpenSearchException Signed-off-by: Nicholas Walter Knize --- .../opensearch/client/GetAliasesResponse.java | 9 +- .../java/org/opensearch/client/SearchIT.java | 5 +- .../documentation/CRUDDocumentationIT.java | 5 +- .../IndicesClientDocumentationIT.java | 3 +- .../TasksClientDocumentationIT.java | 4 +- .../tasks/CancelTasksResponseTests.java | 3 +- .../org/opensearch/BaseExceptionsHelper.java | 24 +- ...xception.java => OpenSearchException.java} | 117 +++-- .../DefaultShardOperationFailedException.java | 7 +- .../opensearch/common/ParsingException.java | 4 +- .../NotSerializableExceptionWrapper.java | 8 +- .../common/io/stream/StreamInput.java | 6 +- .../common/io/stream/StreamOutput.java | 12 +- .../common/io/stream/BaseStreamInput.java | 341 -------------- .../common/io/stream/BaseStreamOutput.java | 150 ------ .../core/common/io/stream/BaseWriteable.java | 150 ------ .../core/common/io/stream/package-info.java | 9 - .../IndexShardSnapshotException.java | 4 +- .../mustache/MultiSearchTemplateResponse.java | 4 +- .../index/rankeval/RankEvalRequestIT.java | 4 +- .../index/rankeval/RankEvalResponse.java | 6 +- .../index/rankeval/RankEvalResponseTests.java | 3 +- ...rossClusterSearchUnavailableClusterIT.java | 13 +- .../admin/cluster/node/tasks/TasksIT.java | 4 +- .../AggregationsIntegrationIT.java | 4 +- .../aggregations/bucket/DateHistogramIT.java | 6 +- .../aggregations/bucket/HistogramIT.java | 6 +- .../bucket/terms/StringTermsIT.java | 5 +- ...on.java => OpenSearchServerException.java} | 439 ++++++++---------- .../action/TaskOperationFailure.java | 3 +- .../indices/close/CloseIndexResponse.java | 4 +- .../readonly/AddIndexBlockResponse.java | 4 +- .../action/bulk/BulkItemResponse.java | 5 +- .../action/get/MultiGetResponse.java | 8 +- .../ingest/SimulateDocumentBaseResult.java | 5 +- .../ingest/SimulateProcessorResult.java | 13 +- .../search/AbstractSearchAsyncAction.java | 6 +- .../action/search/MultiSearchResponse.java | 3 +- .../search/SearchPhaseExecutionException.java | 11 +- .../action/search/ShardSearchFailure.java | 6 +- .../replication/ReplicationResponse.java | 6 +- .../support/tasks/BaseTasksResponse.java | 9 +- .../termvectors/MultiTermVectorsResponse.java | 4 +- .../index/reindex/BulkByScrollResponse.java | 10 +- .../opensearch/rest/BytesRestResponse.java | 7 +- .../transport/TransportService.java | 2 + .../ExceptionSerializationTests.java | 20 +- .../opensearch/OpenSearchExceptionTests.java | 96 ++-- .../action/bulk/BulkItemResponseTests.java | 3 +- .../SearchPhaseExecutionExceptionTests.java | 6 +- .../replication/ReplicationResponseTests.java | 3 +- .../tasks/ListTasksResponseTests.java | 16 +- 52 files changed, 433 insertions(+), 1172 deletions(-) rename libs/core/src/main/java/org/opensearch/{BaseOpenSearchException.java => OpenSearchException.java} (86%) delete mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamInput.java delete mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamOutput.java delete mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseWriteable.java delete mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/stream/package-info.java rename server/src/main/java/org/opensearch/{OpenSearchException.java => OpenSearchServerException.java} (76%) diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java b/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java index 3acd4d515da4f..83b00df73bdc4 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/GetAliasesResponse.java @@ -32,7 +32,6 @@ package org.opensearch.client; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.common.xcontent.StatusToXContentObject; @@ -64,7 +63,7 @@ public class GetAliasesResponse implements StatusToXContentObject { private final RestStatus status; private final String error; - private final BaseOpenSearchException exception; + private final OpenSearchException exception; private final Map> aliases; @@ -75,7 +74,7 @@ public class GetAliasesResponse implements StatusToXContentObject { this.exception = null; } - private GetAliasesResponse(RestStatus status, BaseOpenSearchException exception) { + private GetAliasesResponse(RestStatus status, OpenSearchException exception) { this.status = status; this.error = null; this.aliases = Collections.emptyMap(); @@ -97,7 +96,7 @@ public String getError() { /** * Return the exception that may have been returned */ - public BaseOpenSearchException getException() { + public OpenSearchException getException() { return exception; } @@ -148,7 +147,7 @@ public static GetAliasesResponse fromXContent(XContentParser parser) throws IOEx String currentFieldName; Token token; String error = null; - BaseOpenSearchException exception = null; + OpenSearchException exception = null; RestStatus status = RestStatus.OK; while (parser.nextToken() != Token.END_OBJECT) { diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java index f55b9574e2e33..50c6564ec0fd7 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java @@ -32,7 +32,6 @@ package org.opensearch.client; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchStatusException; import org.opensearch.action.explain.ExplainRequest; @@ -829,8 +828,8 @@ public void testSearchScroll() throws Exception { () -> execute(scrollRequest, highLevelClient()::scroll, highLevelClient()::scrollAsync) ); assertEquals(RestStatus.NOT_FOUND, exception.status()); - assertThat(exception.getRootCause(), instanceOf(BaseOpenSearchException.class)); - BaseOpenSearchException rootCause = (BaseOpenSearchException) exception.getRootCause(); + assertThat(exception.getRootCause(), instanceOf(OpenSearchException.class)); + OpenSearchException rootCause = (OpenSearchException) exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("No search context found for")); } } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java index b198d05e191bb..38addb91f0d41 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/CRUDDocumentationIT.java @@ -33,7 +33,6 @@ package org.opensearch.client.documentation; import org.apache.hc.core5.http.HttpHost; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.DocWriteRequest; @@ -1944,7 +1943,7 @@ public void testMultiGet() throws Exception { // tag::multi-get-indexnotfound assertNull(missingIndexItem.getResponse()); // <1> Exception e = missingIndexItem.getFailure().getFailure(); // <2> - BaseOpenSearchException ee = (BaseOpenSearchException) e; // <3> + OpenSearchException ee = (OpenSearchException) e; // <3> // TODO status is broken! fix in a followup // assertEquals(RestStatus.NOT_FOUND, ee.status()); // <4> assertThat(e.getMessage(), @@ -2036,7 +2035,7 @@ public void onFailure(Exception e) { MultiGetItemResponse item = response.getResponses()[0]; assertNull(item.getResponse()); // <1> Exception e = item.getFailure().getFailure(); // <2> - BaseOpenSearchException ee = (BaseOpenSearchException) e; // <3> + OpenSearchException ee = (OpenSearchException) e; // <3> // TODO status is broken! fix in a followup // assertEquals(RestStatus.CONFLICT, ee.status()); // <4> assertThat(e.getMessage(), diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java index dc5f1d758356c..a1334062064d2 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/IndicesClientDocumentationIT.java @@ -32,7 +32,6 @@ package org.opensearch.client.documentation; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.LatchedActionListener; @@ -1926,7 +1925,7 @@ public void testGetAlias() throws Exception { // tag::get-alias-response-error RestStatus status = response.status(); // <1> - BaseOpenSearchException exception = response.getException(); // <2> + OpenSearchException exception = response.getException(); // <2> String error = response.getError(); // <3> // end::get-alias-response-error diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java index 90b08a70fd917..05479e2e3e81c 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/TasksClientDocumentationIT.java @@ -32,7 +32,7 @@ package org.opensearch.client.documentation; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.LatchedActionListener; import org.opensearch.action.TaskOperationFailure; @@ -124,7 +124,7 @@ public void testListTasks() throws IOException { // end::list-tasks-response-calc // tag::list-tasks-response-failures - List nodeFailures = response.getNodeFailures(); // <1> + List nodeFailures = response.getNodeFailures(); // <1> List taskFailures = response.getTaskFailures(); // <2> // end::list-tasks-response-failures diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java index 85f8f5fc0531f..2a39b0deb8827 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/tasks/CancelTasksResponseTests.java @@ -31,7 +31,6 @@ package org.opensearch.client.tasks; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.TaskOperationFailure; @@ -143,7 +142,7 @@ protected void assertInstances( } // checking failures - List serverNodeFailures = serverTestInstance.getNodeFailures(); + List serverNodeFailures = serverTestInstance.getNodeFailures(); List cNodeFailures = clientInstance.getNodeFailures(); List sExceptionsMessages = serverNodeFailures.stream() .map(x -> org.opensearch.client.tasks.OpenSearchException.buildMessage("exception", x.getMessage(), null)) diff --git a/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java b/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java index a1b65513d3946..129ff99e65458 100644 --- a/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java +++ b/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java @@ -137,7 +137,7 @@ public static String stackTrace(Throwable e) { public static String summaryMessage(Throwable t) { if (t != null) { - if (t instanceof BaseOpenSearchException) { + if (t instanceof OpenSearchException) { return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; } else if (t instanceof IllegalArgumentException) { return "Invalid argument"; @@ -167,8 +167,8 @@ public static void innerToXContent( headerToXContent(builder, entry.getKey().substring(OPENSEARCH_PREFIX_KEY.length()), entry.getValue()); } - if (throwable instanceof BaseOpenSearchException) { - BaseOpenSearchException exception = (BaseOpenSearchException) throwable; + if (throwable instanceof OpenSearchException) { + OpenSearchException exception = (OpenSearchException) throwable; exception.metadataToXContent(builder, params); } @@ -206,8 +206,8 @@ public static void innerToXContent( } /** - * Static toXContent helper method that renders {@link BaseOpenSearchException} or {@link Throwable} instances - * as XContent, delegating the rendering to {@link BaseOpenSearchException#toXContent(XContentBuilder, ToXContent.Params)} + * Static toXContent helper method that renders {@link OpenSearchException} or {@link Throwable} instances + * as XContent, delegating the rendering to {@link OpenSearchException#toXContent(XContentBuilder, ToXContent.Params)} * or {@link #innerToXContent(XContentBuilder, ToXContent.Params, Throwable, String, String, Map, Map, Throwable)}. * * This method is usually used when the {@link Throwable} is rendered as a part of another XContent object, and its result can @@ -216,8 +216,8 @@ public static void innerToXContent( public static void generateThrowableXContent(XContentBuilder builder, ToXContent.Params params, Throwable t) throws IOException { t = unwrapCause(t); - if (t instanceof BaseOpenSearchException) { - ((BaseOpenSearchException) t).toXContent(builder, params); + if (t instanceof OpenSearchException) { + ((OpenSearchException) t).toXContent(builder, params); } else { innerToXContent(builder, params, t, getExceptionName(t), t.getMessage(), emptyMap(), emptyMap(), t.getCause()); } @@ -237,13 +237,9 @@ public static String getExceptionName(Throwable ex) { private static String getExceptionSimpleClassName(final Throwable ex) { String simpleName = ex.getClass().getSimpleName(); - if (Strings.isEmpty(simpleName) && ex instanceof BaseOpenSearchException) { + if (Strings.isEmpty(simpleName)) { simpleName = "OpenSearchException"; } - - if (simpleName.startsWith("BaseOpenSearch")) { - simpleName = simpleName.substring("Base".length()); - } return simpleName; } @@ -298,8 +294,8 @@ protected static void headerToXContent(XContentBuilder builder, String key, List public static RestStatus status(Throwable t) { if (t != null) { - if (t instanceof BaseOpenSearchException) { - return ((BaseOpenSearchException) t).status(); + if (t instanceof OpenSearchException) { + return ((OpenSearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } else if (t instanceof JsonParseException) { diff --git a/libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java b/libs/core/src/main/java/org/opensearch/OpenSearchException.java similarity index 86% rename from libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java rename to libs/core/src/main/java/org/opensearch/OpenSearchException.java index 944566324e44d..e201fe7b1b788 100644 --- a/libs/core/src/main/java/org/opensearch/BaseOpenSearchException.java +++ b/libs/core/src/main/java/org/opensearch/OpenSearchException.java @@ -59,7 +59,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import static org.opensearch.BaseOpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; +import static org.opensearch.OpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; import static org.opensearch.common.xcontent.XContentParserUtils.ensureFieldName; @@ -70,7 +70,7 @@ * * @opensearch.internal */ -public abstract class BaseOpenSearchException extends RuntimeException implements Writeable, ToXContentFragment { +public class OpenSearchException extends RuntimeException implements Writeable, ToXContentFragment { protected static final String ERROR = "error"; protected static final String ROOT_CAUSE = "root_cause"; @@ -85,7 +85,7 @@ public abstract class BaseOpenSearchException extends RuntimeException implement static { registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardSnapshotFailedException.class, org.opensearch.index.snapshots.IndexShardSnapshotFailedException::new, 0, @@ -93,7 +93,7 @@ public abstract class BaseOpenSearchException extends RuntimeException implement ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.ParsingException.class, org.opensearch.common.ParsingException::new, 40, @@ -101,7 +101,7 @@ public abstract class BaseOpenSearchException extends RuntimeException implement ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.io.stream.NotSerializableExceptionWrapper.class, org.opensearch.common.io.stream.NotSerializableExceptionWrapper::new, 62, @@ -111,9 +111,9 @@ public abstract class BaseOpenSearchException extends RuntimeException implement } /** - * Construct a BaseOpenSearchException with the specified cause exception. + * Construct a OpenSearchException with the specified cause exception. */ - public BaseOpenSearchException(Throwable cause) { + public OpenSearchException(Throwable cause) { super(cause); } @@ -126,7 +126,7 @@ public BaseOpenSearchException(Throwable cause) { * @param msg the detail message * @param args the arguments for the message */ - public BaseOpenSearchException(String msg, Object... args) { + public OpenSearchException(String msg, Object... args) { super(LoggerMessageFormat.format(msg, args)); } @@ -141,11 +141,11 @@ public BaseOpenSearchException(String msg, Object... args) { * @param cause the nested exception * @param args the arguments for the message */ - public BaseOpenSearchException(String msg, Throwable cause, Object... args) { + public OpenSearchException(String msg, Throwable cause, Object... args) { super(LoggerMessageFormat.format(msg, args), cause); } - public BaseOpenSearchException(StreamInput in) throws IOException { + public OpenSearchException(StreamInput in) throws IOException { this(in.readOptionalString(), in.readException()); readStackTrace(this, in); headers.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString)); @@ -182,7 +182,7 @@ public static void generateFailureXContent(XContentBuilder builder, ToXContent.P if (detailed == false) { Throwable t = e; for (int counter = 0; counter < 10 && t != null; counter++) { - if (t instanceof BaseOpenSearchException) { + if (t instanceof OpenSearchException) { break; } t = t.getCause(); @@ -192,11 +192,11 @@ public static void generateFailureXContent(XContentBuilder builder, ToXContent.P } // Render the exception with all details - final BaseOpenSearchException[] rootCauses = BaseOpenSearchException.guessRootCauses(e); + final OpenSearchException[] rootCauses = OpenSearchException.guessRootCauses(e); builder.startObject(ERROR); { builder.startArray(ROOT_CAUSE); - for (BaseOpenSearchException rootCause : rootCauses) { + for (OpenSearchException rootCause : rootCauses) { builder.startObject(); rootCause.toXContent( builder, @@ -212,14 +212,14 @@ public static void generateFailureXContent(XContentBuilder builder, ToXContent.P /** * Returns the root cause of this exception or multiple if different shards caused different exceptions. - * If the given exception is not an instance of {@link BaseOpenSearchException} an empty array + * If the given exception is not an instance of {@link OpenSearchException} an empty array * is returned. */ - public static BaseOpenSearchException[] guessRootCauses(Throwable t) { + public static OpenSearchException[] guessRootCauses(Throwable t) { Throwable ex = BaseExceptionsHelper.unwrapCause(t); - if (ex instanceof BaseOpenSearchException) { + if (ex instanceof OpenSearchException) { // OpenSearchException knows how to guess its own root cause - return ((BaseOpenSearchException) ex).guessRootCauses(); + return ((OpenSearchException) ex).guessRootCauses(); } if (ex instanceof XContentParseException) { /* @@ -232,12 +232,12 @@ public static BaseOpenSearchException[] guessRootCauses(Throwable t) { */ Throwable cause = ex.getCause(); if (cause != null) { - if (cause instanceof XContentParseException || cause instanceof BaseOpenSearchException) { - return BaseOpenSearchException.guessRootCauses(ex.getCause()); + if (cause instanceof XContentParseException || cause instanceof OpenSearchException) { + return OpenSearchException.guessRootCauses(ex.getCause()); } } } - return new BaseOpenSearchException[] { new BaseOpenSearchException(ex.getMessage(), ex) { + return new OpenSearchException[] { new OpenSearchException(ex.getMessage(), ex) { @Override protected String getExceptionName() { return BaseExceptionsHelper.getExceptionName(getCause()); @@ -354,8 +354,8 @@ public String getDetailedMessage() { if (getCause() != null) { StringBuilder sb = new StringBuilder(); sb.append(toString()).append("; "); - if (getCause() instanceof BaseOpenSearchException) { - sb.append(((BaseOpenSearchException) getCause()).getDetailedMessage()); + if (getCause() instanceof OpenSearchException) { + sb.append(((OpenSearchException) getCause()).getDetailedMessage()); } else { sb.append(getCause()); } @@ -400,12 +400,12 @@ protected String getExceptionName() { /** * Returns the root cause of this exception or multiple if different shards caused different exceptions */ - public BaseOpenSearchException[] guessRootCauses() { + public OpenSearchException[] guessRootCauses() { final Throwable cause = getCause(); - if (cause != null && cause instanceof BaseOpenSearchException) { - return ((BaseOpenSearchException) cause).guessRootCauses(); + if (cause != null && cause instanceof OpenSearchException) { + return ((OpenSearchException) cause).guessRootCauses(); } - return new BaseOpenSearchException[] { this }; + return new OpenSearchException[] { this }; } public void setResources(String type, String... id) { @@ -524,8 +524,8 @@ static int[] ids() { * @return an array of all registered pairs of handle IDs and exception classes */ @SuppressWarnings("unchecked") - static Tuple>[] classes() { - final Tuple>[] ts = OpenSearchExceptionHandleRegistry.handles() + static Tuple>[] classes() { + final Tuple>[] ts = OpenSearchExceptionHandleRegistry.handles() .stream() .map(h -> Tuple.tuple(h.id, h.exceptionClass)) .toArray(Tuple[]::new); @@ -579,13 +579,13 @@ public void setShard(ShardId shardId) { * * @opensearch.internal */ - protected static class BaseOpenSearchExceptionHandle { - final Class exceptionClass; - final CheckedFunction constructor; + protected static class OpenSearchExceptionHandle { + final Class exceptionClass; + final CheckedFunction constructor; final int id; final Version versionAdded; - BaseOpenSearchExceptionHandle( + OpenSearchExceptionHandle( Class exceptionClass, CheckedFunction constructor, int id, @@ -600,10 +600,10 @@ BaseOpenSearchExceptionHandle( } @SuppressWarnings("unchecked") - public static BaseOpenSearchException readException(T input, int id) throws IOException { - CheckedFunction opensearchException = (CheckedFunction< + public static OpenSearchException readException(T input, int id) throws IOException { + CheckedFunction opensearchException = (CheckedFunction< T, - ? extends BaseOpenSearchException, + ? extends OpenSearchException, IOException>) OpenSearchExceptionHandleRegistry.getSupplier(id); if (opensearchException == null) { throw new IllegalStateException("unknown exception for id: " + id); @@ -652,7 +652,7 @@ public static T writeStackTraces( /** * Returns the serialization id the given exception. */ - public static int getId(final Class exception) { + public static int getId(final Class exception) { return OpenSearchExceptionHandleRegistry.getId(exception); } @@ -664,13 +664,13 @@ public static boolean isRegistered(final Class exception, V } /** - * Generate a {@link BaseOpenSearchException} from a {@link XContentParser}. This does not + * Generate a {@link OpenSearchException} from a {@link XContentParser}. This does not * return the original exception type (ie NodeClosedException for example) but just wraps * the type, the reason and the cause of the exception. It also recursively parses the - * tree structure of the cause, returning it as a tree structure of {@link BaseOpenSearchException} + * tree structure of the cause, returning it as a tree structure of {@link OpenSearchException} * instances. */ - public static BaseOpenSearchException fromXContent(XContentParser parser) throws IOException { + public static OpenSearchException fromXContent(XContentParser parser) throws IOException { XContentParser.Token token = parser.nextToken(); ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); return innerFromXContent(parser, false); @@ -679,13 +679,13 @@ public static BaseOpenSearchException fromXContent(XContentParser parser) throws /** * Parses the output of {@link #generateFailureXContent(XContentBuilder, Params, Exception, boolean)} */ - public static BaseOpenSearchException failureFromXContent(XContentParser parser) throws IOException { + public static OpenSearchException failureFromXContent(XContentParser parser) throws IOException { XContentParser.Token token = parser.currentToken(); ensureFieldName(parser, token, ERROR); token = parser.nextToken(); if (token.isValue()) { - return new BaseOpenSearchException(buildMessage("exception", parser.text(), null)) { + return new OpenSearchException(buildMessage("exception", parser.text(), null)) { }; } @@ -696,16 +696,16 @@ public static BaseOpenSearchException failureFromXContent(XContentParser parser) return innerFromXContent(parser, true); } - public static BaseOpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException { + public static OpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException { XContentParser.Token token = parser.currentToken(); ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); String type = null, reason = null, stack = null; - BaseOpenSearchException cause = null; + OpenSearchException cause = null; Map> metadata = new HashMap<>(); Map> headers = new HashMap<>(); - List rootCauses = new ArrayList<>(); - List suppressed = new ArrayList<>(); + List rootCauses = new ArrayList<>(); + List suppressed = new ArrayList<>(); for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) { String currentFieldName = parser.currentName(); @@ -782,7 +782,7 @@ public static BaseOpenSearchException innerFromXContent(XContentParser parser, b } } - BaseOpenSearchException e = new BaseOpenSearchException(buildMessage(type, reason, stack), cause) { + OpenSearchException e = new OpenSearchException(buildMessage(type, reason, stack), cause) { }; for (Map.Entry> entry : metadata.entrySet()) { // subclasses can print out additional metadata through the metadataToXContent method. Simple key-value pairs will be @@ -799,16 +799,16 @@ public static BaseOpenSearchException innerFromXContent(XContentParser parser, b // Adds root causes as suppressed exception. This way they are not lost // after parsing and can be retrieved using getSuppressed() method. - for (BaseOpenSearchException rootCause : rootCauses) { + for (OpenSearchException rootCause : rootCauses) { e.addSuppressed(rootCause); } - for (BaseOpenSearchException s : suppressed) { + for (OpenSearchException s : suppressed) { e.addSuppressed(s); } return e; } - static Set> getRegisteredKeys() { // for testing + static Set> getRegisteredKeys() { // for testing return OpenSearchExceptionHandleRegistry.getRegisteredKeys(); } @@ -821,26 +821,25 @@ public static class OpenSearchExceptionHandleRegistry { /** Registry mapping from unique Ordinal to the Exception Constructor */ private static final Map< Integer, - CheckedFunction> ID_TO_SUPPLIER_REGISTRY = - new ConcurrentHashMap<>(); + CheckedFunction> ID_TO_SUPPLIER_REGISTRY = new ConcurrentHashMap<>(); /** Registry mapping from Exception class to the Exception Handler */ private static final Map< - Class, - BaseOpenSearchExceptionHandle> CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY = new ConcurrentHashMap<>(); + Class, + OpenSearchExceptionHandle> CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY = new ConcurrentHashMap<>(); /** returns the Exception constructor function from a given ordinal */ - public static CheckedFunction getSupplier(final int id) { + public static CheckedFunction getSupplier(final int id) { return ID_TO_SUPPLIER_REGISTRY.get(id); } /** registers the Exception handler */ - public static void registerExceptionHandle(final BaseOpenSearchExceptionHandle handle) { + public static void registerExceptionHandle(final OpenSearchExceptionHandle handle) { ID_TO_SUPPLIER_REGISTRY.put(handle.id, handle.constructor); CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.put(handle.exceptionClass, handle); } /** Gets the unique ordinal id of the Exception from the given class */ - public static int getId(final Class exception) { + public static int getId(final Class exception) { return CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.get(exception).id; } @@ -850,13 +849,13 @@ public static Set ids() { } /** returns a collection of handles */ - public static Collection handles() { + public static Collection handles() { return CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.values(); } /** checks that the exception class is registered */ public static boolean isRegistered(final Class exception, final Version version) { - BaseOpenSearchExceptionHandle openSearchExceptionHandle = CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.get(exception); + OpenSearchExceptionHandle openSearchExceptionHandle = CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.get(exception); if (openSearchExceptionHandle != null) { return version.onOrAfter(openSearchExceptionHandle.versionAdded); } @@ -864,7 +863,7 @@ public static boolean isRegistered(final Class exception, f } /** returns a set of registered exception classes */ - public static Set> getRegisteredKeys() { // for testing + public static Set> getRegisteredKeys() { // for testing return CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.keySet(); } } diff --git a/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java index 6608d61ebf8a7..3f958a50661bd 100644 --- a/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java +++ b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java @@ -33,8 +33,7 @@ package org.opensearch.action.support; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -70,7 +69,7 @@ public class DefaultShardOperationFailedException extends ShardOperationFailedEx protected static void declareFields(ConstructingObjectParser objectParser) { objectParser.declareString(constructorArg(), new ParseField(INDEX)); objectParser.declareInt(constructorArg(), new ParseField(SHARD_ID)); - objectParser.declareObject(constructorArg(), (p, c) -> BaseOpenSearchException.fromXContent(p), new ParseField(REASON)); + objectParser.declareObject(constructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField(REASON)); } static { @@ -83,7 +82,7 @@ protected DefaultShardOperationFailedException(StreamInput in) throws IOExceptio readFrom(in, this); } - public DefaultShardOperationFailedException(BaseOpenSearchException e) { + public DefaultShardOperationFailedException(OpenSearchException e) { super( e.getIndex() == null ? null : e.getIndex().getName(), e.getShardId() == null ? -1 : e.getShardId().getId(), diff --git a/libs/core/src/main/java/org/opensearch/common/ParsingException.java b/libs/core/src/main/java/org/opensearch/common/ParsingException.java index c2a8c1ce8230f..5991cc3d77eff 100644 --- a/libs/core/src/main/java/org/opensearch/common/ParsingException.java +++ b/libs/core/src/main/java/org/opensearch/common/ParsingException.java @@ -32,7 +32,7 @@ package org.opensearch.common; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.core.xcontent.ToXContent; @@ -50,7 +50,7 @@ * * @opensearch.internal */ -public class ParsingException extends BaseOpenSearchException { +public class ParsingException extends OpenSearchException { protected static final int UNKNOWN_POSITION = -1; private final int lineNumber; diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java b/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java index 3dd4b9e66fe9f..590f9c2a03d57 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java @@ -33,7 +33,7 @@ package org.opensearch.common.io.stream; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.rest.RestStatus; import java.io.IOException; @@ -47,7 +47,7 @@ * * @opensearch.internal */ -public final class NotSerializableExceptionWrapper extends BaseOpenSearchException { +public final class NotSerializableExceptionWrapper extends OpenSearchException { private final String name; private final RestStatus status; @@ -60,8 +60,8 @@ public NotSerializableExceptionWrapper(Throwable other) { for (Throwable otherSuppressed : other.getSuppressed()) { addSuppressed(otherSuppressed); } - if (other instanceof BaseOpenSearchException) { - BaseOpenSearchException ex = (BaseOpenSearchException) other; + if (other instanceof OpenSearchException) { + OpenSearchException ex = (OpenSearchException) other; for (String key : ex.getHeaderKeys()) { this.addHeader(key, ex.getHeader(key)); } diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java index c3af941cd4418..c528d70ca9a6d 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java @@ -41,8 +41,8 @@ import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; -import org.opensearch.BaseOpenSearchException; import org.opensearch.Build; +import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.common.CharArrays; import org.opensearch.common.Nullable; @@ -89,7 +89,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.IntFunction; -import static org.opensearch.BaseOpenSearchException.readStackTrace; +import static org.opensearch.OpenSearchException.readStackTrace; /** * A stream from this node to another node. Technically, it can also be streamed to a byte array but that is mostly for testing. @@ -981,7 +981,7 @@ public T readException() throws IOException { switch (key) { case 0: final int ord = readVInt(); - return (T) BaseOpenSearchException.readException(this, ord); + return (T) OpenSearchException.readException(this, ord); case 1: String msg1 = readOptionalString(); String resource1 = readOptionalString(); diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java index c69fe6e93f550..888c7530c4146 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamOutput.java @@ -40,8 +40,8 @@ import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.opensearch.BaseOpenSearchException; import org.opensearch.Build; +import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.common.CharArrays; import org.opensearch.common.Nullable; @@ -1065,14 +1065,14 @@ private void writeException(Throwable rootException, Throwable throwable, int ne writeBoolean(((OpenSearchRejectedExecutionException) throwable).isExecutorShutdown()); writeCause = false; } else { - final BaseOpenSearchException ex; - if (throwable instanceof BaseOpenSearchException && BaseOpenSearchException.isRegistered(throwable.getClass(), version)) { - ex = (BaseOpenSearchException) throwable; + final OpenSearchException ex; + if (throwable instanceof OpenSearchException && OpenSearchException.isRegistered(throwable.getClass(), version)) { + ex = (OpenSearchException) throwable; } else { ex = new NotSerializableExceptionWrapper(throwable); } writeVInt(0); - writeVInt(BaseOpenSearchException.getId(ex.getClass())); + writeVInt(OpenSearchException.getId(ex.getClass())); ex.writeTo(this); return; } @@ -1082,7 +1082,7 @@ private void writeException(Throwable rootException, Throwable throwable, int ne if (writeCause) { writeException(rootException, throwable.getCause(), nestedLevel + 1); } - BaseOpenSearchException.writeStackTraces(throwable, this, (o, t) -> o.writeException(rootException, t, nestedLevel + 1)); + OpenSearchException.writeStackTraces(throwable, this, (o, t) -> o.writeException(rootException, t, nestedLevel + 1)); } } diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamInput.java b/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamInput.java deleted file mode 100644 index 178333d529cf6..0000000000000 --- a/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamInput.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ -package org.opensearch.core.common.io.stream; - -import org.apache.lucene.util.ArrayUtil; -import org.apache.lucene.util.CharsRef; -import org.opensearch.Version; -import org.opensearch.common.Nullable; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.Locale; -import java.util.function.IntFunction; - -/** - * Foundation class for reading core types off the transport stream - * - * todo: refactor {@code StreamInput} primitive readers to this class - * - * @opensearch.internal - */ -public abstract class BaseStreamInput extends InputStream { - // Maximum char-count to de-serialize via the thread-local CharsRef buffer - private static final int SMALL_STRING_LIMIT = 1024; - // Reusable bytes for deserializing strings - private static final ThreadLocal stringReadBuffer = ThreadLocal.withInitial(() -> new byte[1024]); - // Thread-local buffer for smaller strings - private static final ThreadLocal smallSpare = ThreadLocal.withInitial(() -> new CharsRef(SMALL_STRING_LIMIT)); - private Version version = Version.CURRENT; - // Larger buffer used for long strings that can't fit into the thread-local buffer - // We don't use a CharsRefBuilder since we exactly know the size of the character array up front - // this prevents calling grow for every character since we don't need this - private CharsRef largeSpare; - - /** - * The version of the node on the other side of this stream. - */ - public Version getVersion() { - return this.version; - } - - /** - * Set the version of the node on the other side of this stream. - */ - public void setVersion(Version version) { - this.version = version; - } - - /** - * Closes the stream to further operations. - */ - @Override - public abstract void close() throws IOException; - - @Override - public abstract int available() throws IOException; - - /** - * This method throws an {@link EOFException} if the given number of bytes can not be read from the this stream. This method might - * be a no-op depending on the underlying implementation if the information of the remaining bytes is not present. - */ - protected abstract void ensureCanReadBytes(int length) throws EOFException; - - /** - * Reads and returns a single byte. - */ - public abstract byte readByte() throws IOException; - - /** - * Reads a specified number of bytes into an array at the specified offset. - * - * @param b the array to read bytes into - * @param offset the offset in the array to start storing bytes - * @param len the number of bytes to read - */ - public abstract void readBytes(byte[] b, int offset, int len) throws IOException; - - public void readFully(byte[] b) throws IOException { - readBytes(b, 0, b.length); - } - - protected boolean readBoolean(final byte value) { - if (value == 0) { - return false; - } else if (value == 1) { - return true; - } else { - final String message = String.format(Locale.ROOT, "unexpected byte [0x%02x]", value); - throw new IllegalStateException(message); - } - } - - /** - * Reads a boolean. - */ - public final boolean readBoolean() throws IOException { - return readBoolean(readByte()); - } - - @Nullable - public final Boolean readOptionalBoolean() throws IOException { - final byte value = readByte(); - if (value == 2) { - return null; - } else { - return readBoolean(value); - } - } - - /** - * Reads four bytes and returns an int. - */ - public int readInt() throws IOException { - return ((readByte() & 0xFF) << 24) | ((readByte() & 0xFF) << 16) | ((readByte() & 0xFF) << 8) | (readByte() & 0xFF); - } - - /** - * Reads an int stored in variable-length format. Reads between one and - * five bytes. Smaller values take fewer bytes. Negative numbers - * will always use all 5 bytes and are therefore better serialized - * using {@link #readInt} - */ - public int readVInt() throws IOException { - byte b = readByte(); - int i = b & 0x7F; - if ((b & 0x80) == 0) { - return i; - } - b = readByte(); - i |= (b & 0x7F) << 7; - if ((b & 0x80) == 0) { - return i; - } - b = readByte(); - i |= (b & 0x7F) << 14; - if ((b & 0x80) == 0) { - return i; - } - b = readByte(); - i |= (b & 0x7F) << 21; - if ((b & 0x80) == 0) { - return i; - } - b = readByte(); - if ((b & 0x80) != 0) { - throw new IOException("Invalid vInt ((" + Integer.toHexString(b) + " & 0x7f) << 28) | " + Integer.toHexString(i)); - } - return i | ((b & 0x7F) << 28); - } - - @Nullable - public Integer readOptionalVInt() throws IOException { - if (readBoolean()) { - return readVInt(); - } - return null; - } - - public String readString() throws IOException { - final int charCount = readArraySize(); - final CharsRef charsRef; - if (charCount > SMALL_STRING_LIMIT) { - if (largeSpare == null) { - largeSpare = new CharsRef(ArrayUtil.oversize(charCount, Character.BYTES)); - } else if (largeSpare.chars.length < charCount) { - // we don't use ArrayUtils.grow since there is no need to copy the array - largeSpare.chars = new char[ArrayUtil.oversize(charCount, Character.BYTES)]; - } - charsRef = largeSpare; - } else { - charsRef = smallSpare.get(); - } - charsRef.length = charCount; - int charsOffset = 0; - int offsetByteArray = 0; - int sizeByteArray = 0; - int missingFromPartial = 0; - final byte[] byteBuffer = stringReadBuffer.get(); - final char[] charBuffer = charsRef.chars; - for (; charsOffset < charCount;) { - final int charsLeft = charCount - charsOffset; - int bufferFree = byteBuffer.length - sizeByteArray; - // Determine the minimum amount of bytes that are left in the string - final int minRemainingBytes; - if (missingFromPartial > 0) { - // One byte for each remaining char except for the already partially read char - minRemainingBytes = missingFromPartial + charsLeft - 1; - missingFromPartial = 0; - } else { - // Each char has at least a single byte - minRemainingBytes = charsLeft; - } - final int toRead; - if (bufferFree < minRemainingBytes) { - // We don't have enough space left in the byte array to read as much as we'd like to so we free up as many bytes in the - // buffer by moving unused bytes that didn't make up a full char in the last iteration to the beginning of the buffer, - // if there are any - if (offsetByteArray > 0) { - sizeByteArray = sizeByteArray - offsetByteArray; - switch (sizeByteArray) { // We only have 0, 1 or 2 => no need to bother with a native call to System#arrayCopy - case 1: - byteBuffer[0] = byteBuffer[offsetByteArray]; - break; - case 2: - byteBuffer[0] = byteBuffer[offsetByteArray]; - byteBuffer[1] = byteBuffer[offsetByteArray + 1]; - break; - } - assert sizeByteArray <= 2 : "We never copy more than 2 bytes here since a char is 3 bytes max"; - toRead = Math.min(bufferFree + offsetByteArray, minRemainingBytes); - offsetByteArray = 0; - } else { - toRead = bufferFree; - } - } else { - toRead = minRemainingBytes; - } - readBytes(byteBuffer, sizeByteArray, toRead); - sizeByteArray += toRead; - // As long as we at least have three bytes buffered we don't need to do any bounds checking when getting the next char since we - // read 3 bytes per char/iteration at most - for (; offsetByteArray < sizeByteArray - 2; offsetByteArray++) { - final int c = byteBuffer[offsetByteArray] & 0xff; - switch (c >> 4) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - charBuffer[charsOffset++] = (char) c; - break; - case 12: - case 13: - charBuffer[charsOffset++] = (char) ((c & 0x1F) << 6 | byteBuffer[++offsetByteArray] & 0x3F); - break; - case 14: - charBuffer[charsOffset++] = (char) ((c & 0x0F) << 12 | (byteBuffer[++offsetByteArray] & 0x3F) << 6 - | (byteBuffer[++offsetByteArray] & 0x3F)); - break; - default: - BaseStreamInput.throwOnBrokenChar(c); - } - } - // try to extract chars from remaining bytes with bounds checks for multi-byte chars - final int bufferedBytesRemaining = sizeByteArray - offsetByteArray; - for (int i = 0; i < bufferedBytesRemaining; i++) { - final int c = byteBuffer[offsetByteArray] & 0xff; - switch (c >> 4) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - charBuffer[charsOffset++] = (char) c; - offsetByteArray++; - break; - case 12: - case 13: - missingFromPartial = 2 - (bufferedBytesRemaining - i); - if (missingFromPartial == 0) { - offsetByteArray++; - charBuffer[charsOffset++] = (char) ((c & 0x1F) << 6 | byteBuffer[offsetByteArray++] & 0x3F); - } - ++i; - break; - case 14: - missingFromPartial = 3 - (bufferedBytesRemaining - i); - ++i; - break; - default: - BaseStreamInput.throwOnBrokenChar(c); - } - } - } - return charsRef.toString(); - } - - @Nullable - public String readOptionalString() throws IOException { - if (readBoolean()) { - return readString(); - } - return null; - } - - private static void throwOnBrokenChar(int c) throws IOException { - throw new IOException("Invalid string; unexpected character: " + c + " hex: " + Integer.toHexString(c)); - } - - /** - * Reads a vint via {@link #readVInt()} and applies basic checks to ensure the read array size is sane. - * This method uses {@link #ensureCanReadBytes(int)} to ensure this stream has enough bytes to read for the read array size. - */ - protected int readArraySize() throws IOException { - final int arraySize = readVInt(); - if (arraySize > ArrayUtil.MAX_ARRAY_LENGTH) { - throw new IllegalStateException("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: " + arraySize); - } - if (arraySize < 0) { - throw new NegativeArraySizeException("array size must be positive but was: " + arraySize); - } - // lets do a sanity check that if we are reading an array size that is bigger that the remaining bytes we can safely - // throw an exception instead of allocating the array based on the size. A simple corrutpted byte can make a node go OOM - // if the size is large and for perf reasons we allocate arrays ahead of time - ensureCanReadBytes(arraySize); - return arraySize; - } - - /** - * Reads a collection of objects - */ - @SuppressWarnings("unchecked") - protected > C readCollection( - BaseWriteable.Reader reader, - IntFunction constructor, - C empty - ) throws IOException { - int count = readArraySize(); - if (count == 0) { - return empty; - } - C builder = constructor.apply(count); - for (int i = 0; i < count; i++) { - builder.add(reader.read((S) this)); - } - return builder; - } -} diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamOutput.java b/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamOutput.java deleted file mode 100644 index e2d4edf0a6023..0000000000000 --- a/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseStreamOutput.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ -package org.opensearch.core.common.io.stream; - -import org.opensearch.Version; -import org.opensearch.common.Nullable; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Foundation class for writing core types over the transport stream - * - * todo: refactor {@code StreamOutput} primitive writers to this class - * - * @opensearch.internal - */ -public abstract class BaseStreamOutput extends OutputStream { - protected static final ThreadLocal scratch = ThreadLocal.withInitial(() -> new byte[1024]); - private static byte ZERO = 0; - private static byte ONE = 1; - private static byte TWO = 2; - protected Version version = Version.CURRENT; - - /** - * The version of the node on the other side of this stream. - */ - public Version getVersion() { - return this.version; - } - - /** - * Set the version of the node on the other side of this stream. - */ - public void setVersion(Version version) { - this.version = version; - } - - /** - * Closes this stream to further operations. - */ - @Override - public abstract void close() throws IOException; - - /** - * Forces any buffered output to be written. - */ - @Override - public abstract void flush() throws IOException; - - public abstract void reset() throws IOException; - - /** - * Writes a single byte. - */ - public abstract void writeByte(byte b) throws IOException; - - /** - * Writes an array of bytes. - * - * @param b the bytes to write - * @param offset the offset in the byte array - * @param length the number of bytes to write - */ - public abstract void writeBytes(byte[] b, int offset, int length) throws IOException; - - /** - * Writes a boolean. - */ - public void writeBoolean(boolean b) throws IOException { - writeByte(b ? ONE : ZERO); - } - - public void writeOptionalBoolean(@Nullable Boolean b) throws IOException { - if (b == null) { - writeByte(TWO); - } else { - writeBoolean(b); - } - } - - /** - * Writes an int as four bytes. - */ - public void writeInt(int i) throws IOException { - final byte[] buffer = scratch.get(); - buffer[0] = (byte) (i >> 24); - buffer[1] = (byte) (i >> 16); - buffer[2] = (byte) (i >> 8); - buffer[3] = (byte) i; - writeBytes(buffer, 0, 4); - } - - /** - * Writes an optional {@link Integer}. - */ - public void writeOptionalInt(@Nullable Integer integer) throws IOException { - if (integer == null) { - writeBoolean(false); - } else { - writeBoolean(true); - writeInt(integer); - } - } - - /** - * Writes an int in a variable-length format. Writes between one and - * five bytes. Smaller values take fewer bytes. Negative numbers - * will always use all 5 bytes and are therefore better serialized - * using {@link #writeInt} - */ - public void writeVInt(int i) throws IOException { - /* - * Shortcut writing single byte because it is very, very common and - * can skip grabbing the scratch buffer. This is marginally slower - * than hand unrolling the entire encoding loop but hand unrolling - * the encoding loop blows out the method size so it can't be inlined. - * In that case benchmarks of the method itself are faster but - * benchmarks of methods that use this method are slower. - * This is philosophically in line with vint in general - it biases - * twoards being simple and fast for smaller numbers. - */ - if (Integer.numberOfLeadingZeros(i) >= 25) { - writeByte((byte) i); - return; - } - byte[] buffer = scratch.get(); - int index = 0; - do { - buffer[index++] = ((byte) ((i & 0x7f) | 0x80)); - i >>>= 7; - } while ((i & ~0x7F) != 0); - buffer[index++] = ((byte) i); - writeBytes(buffer, 0, index); - } - - public void writeOptionalVInt(@Nullable Integer integer) throws IOException { - if (integer == null) { - writeBoolean(false); - } else { - writeBoolean(true); - writeVInt(integer); - } - } -} diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseWriteable.java b/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseWriteable.java deleted file mode 100644 index fbb8d4120f31d..0000000000000 --- a/libs/core/src/main/java/org/opensearch/core/common/io/stream/BaseWriteable.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ -package org.opensearch.core.common.io.stream; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Implementers can be written to a {@code StreamOutput} and read from a {@code StreamInput}. This allows them to be "thrown - * across the wire" using OpenSearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by - * serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged. - * - * @opensearch.internal - */ -public interface BaseWriteable { - /** - * A WriteableRegistry registers {@link Writer} methods for writing data types over a - * {@link BaseStreamOutput} channel and {@link Reader} methods for reading data from a - * {@link BaseStreamInput} channel. - * - * @opensearch.internal - */ - class WriteableRegistry { - private static final Map, Writer> WRITER_REGISTRY = new ConcurrentHashMap<>(); - private static final Map, Class> WRITER_CUSTOM_CLASS_MAP = new ConcurrentHashMap<>(); - private static final Map> READER_REGISTRY = new ConcurrentHashMap<>(); - - /** - * registers a streamable writer - * - * @opensearch.internal - */ - public static > void registerWriter(final Class clazz, final W writer) { - if (WRITER_REGISTRY.putIfAbsent(clazz, writer) != null) { - throw new IllegalArgumentException("Streamable writer already registered for type [" + clazz.getName() + "]"); - } - } - - /** - * registers a streamable reader - * - * @opensearch.internal - */ - public static > void registerReader(final byte ordinal, final R reader) { - if (READER_REGISTRY.putIfAbsent(ordinal, reader) != null) { - throw new IllegalArgumentException("Streamable reader already registered for ordinal [" + (int) ordinal + "]"); - } - } - - public static void registerClassAlias(final Class classInstance, final Class classGeneric) { - if (WRITER_CUSTOM_CLASS_MAP.putIfAbsent(classInstance, classGeneric) != null) { - throw new IllegalArgumentException("Streamable custom class already registered [" + classInstance.getClass() + "]"); - } - } - - /** - * Returns the registered writer keyed by the class type - */ - @SuppressWarnings("unchecked") - public static > W getWriter(final Class clazz) { - return (W) WRITER_REGISTRY.get(clazz); - } - - /** - * Returns the ristered reader keyed by the unique ordinal - */ - @SuppressWarnings("unchecked") - public static > R getReader(final byte b) { - return (R) READER_REGISTRY.get(b); - } - - public static Class getCustomClassFromInstance(final Object value) { - if (value == null) { - throw new IllegalArgumentException("Attempting to retrieve a class type from a null value"); - } - // rip through registered classes; return the class iff 'value' is an instance - // we do it this way to cover inheritance and interfaces (e.g., joda DateTime is an instanceof - // a ReadableInstant interface) - for (final Class clazz : WRITER_CUSTOM_CLASS_MAP.values()) { - if (clazz.isInstance(value)) { - return clazz; - } - } - return null; - } - } - - /** - * Write this into the {@linkplain BaseStreamOutput}. - */ - void writeTo(final S out) throws IOException; - - /** - * Reference to a method that can write some object to a {@link BaseStreamOutput}. - *

- * By convention this is a method from {@link BaseStreamOutput} itself (e.g., {@code StreamOutput#writeString}). If the value can be - * {@code null}, then the "optional" variant of methods should be used! - *

- * Most classes should implement {@code Writeable} and the {@code Writeable#writeTo(BaseStreamOutput)} method should use - * {@link BaseStreamOutput} methods directly or this indirectly: - *


-     * public void writeTo(StreamOutput out) throws IOException {
-     *     out.writeVInt(someValue);
-     *     out.writeMapOfLists(someMap, StreamOutput::writeString, StreamOutput::writeString);
-     * }
-     * 
- */ - @FunctionalInterface - interface Writer { - - /** - * Write {@code V}-type {@code value} to the {@code out}put stream. - * - * @param out Output to write the {@code value} too - * @param value The value to add - */ - void write(final S out, V value) throws IOException; - } - - /** - * Reference to a method that can read some object from a stream. By convention this is a constructor that takes - * {@linkplain BaseStreamInput} as an argument for most classes and a static method for things like enums. Returning null from one of these - * is always wrong - for that we use methods like {@code StreamInput#readOptionalWriteable(Reader)}. - *

- * As most classes will implement this via a constructor (or a static method in the case of enumerations), it's something that should - * look like: - *


-     * public MyClass(final StreamInput in) throws IOException {
-     *     this.someValue = in.readVInt();
-     *     this.someMap = in.readMapOfLists(StreamInput::readString, StreamInput::readString);
-     * }
-     * 
- */ - @FunctionalInterface - interface Reader { - - /** - * Read {@code V}-type value from a stream. - * - * @param in Input to read the value from - */ - V read(final S in) throws IOException; - } -} diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/stream/package-info.java b/libs/core/src/main/java/org/opensearch/core/common/io/stream/package-info.java deleted file mode 100644 index 76d0842466b96..0000000000000 --- a/libs/core/src/main/java/org/opensearch/core/common/io/stream/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ -/** Core transport stream classes */ -package org.opensearch.core.common.io.stream; diff --git a/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java b/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java index 82d57309fe922..0d8001ec3d730 100644 --- a/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java +++ b/libs/core/src/main/java/org/opensearch/index/snapshots/IndexShardSnapshotException.java @@ -32,7 +32,7 @@ package org.opensearch.index.snapshots; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.index.shard.ShardId; @@ -43,7 +43,7 @@ * * @opensearch.internal */ -public class IndexShardSnapshotException extends BaseOpenSearchException { +public class IndexShardSnapshotException extends OpenSearchException { public IndexShardSnapshotException(ShardId shardId, String msg) { this(shardId, msg, null); } diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java index 5b6102d1a3ad4..449e89cdc5f3c 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java @@ -32,7 +32,7 @@ package org.opensearch.script.mustache; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.search.MultiSearchResponse; import org.opensearch.common.Nullable; @@ -166,7 +166,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par for (Item item : items) { if (item.isFailure()) { builder.startObject(); - BaseOpenSearchException.generateFailureXContent(builder, params, item.getFailure(), true); + OpenSearchException.generateFailureXContent(builder, params, item.getFailure(), true); builder.endObject(); } else { item.getResponse().toXContent(builder, params); diff --git a/modules/rank-eval/src/internalClusterTest/java/org/opensearch/index/rankeval/RankEvalRequestIT.java b/modules/rank-eval/src/internalClusterTest/java/org/opensearch/index/rankeval/RankEvalRequestIT.java index 35ceb60dec7ed..6eb974c77a5f3 100644 --- a/modules/rank-eval/src/internalClusterTest/java/org/opensearch/index/rankeval/RankEvalRequestIT.java +++ b/modules/rank-eval/src/internalClusterTest/java/org/opensearch/index/rankeval/RankEvalRequestIT.java @@ -32,7 +32,7 @@ package org.opensearch.index.rankeval; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.support.IndicesOptions; @@ -274,7 +274,7 @@ public void testBadQuery() { RankEvalResponse response = client().execute(RankEvalAction.INSTANCE, builder.request()).actionGet(); assertEquals(1, response.getFailures().size()); - BaseOpenSearchException[] rootCauses = BaseOpenSearchException.guessRootCauses(response.getFailures().get("broken_query")); + OpenSearchException[] rootCauses = OpenSearchException.guessRootCauses(response.getFailures().get("broken_query")); assertEquals("java.lang.NumberFormatException: For input string: \"noStringOnNumericFields\"", rootCauses[0].getCause().toString()); } diff --git a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java index c3f9fa01a047b..180069ab91bd6 100644 --- a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java +++ b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java @@ -32,7 +32,7 @@ package org.opensearch.index.rankeval; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; @@ -136,7 +136,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject("failures"); for (String key : failures.keySet()) { builder.startObject(key); - BaseOpenSearchException.generateFailureXContent(builder, params, failures.get(key), true); + OpenSearchException.generateFailureXContent(builder, params, failures.get(key), true); builder.endObject(); } builder.endObject(); @@ -166,7 +166,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws PARSER.declareNamedObjects(ConstructingObjectParser.optionalConstructorArg(), (p, c, n) -> { XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, p.nextToken(), p); XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p); - Tuple tuple = new Tuple<>(n, BaseOpenSearchException.failureFromXContent(p)); + Tuple tuple = new Tuple<>(n, OpenSearchException.failureFromXContent(p)); XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, p.nextToken(), p); return tuple; }, FAILURES_FIELD); diff --git a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java index 5183d1df8f82e..1819e7d1369c8 100644 --- a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java +++ b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java @@ -32,7 +32,6 @@ package org.opensearch.index.rankeval; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.search.SearchPhaseExecutionException; @@ -167,7 +166,7 @@ public void testXContentParsing() throws IOException { assertEquals(testItem.getFailures().keySet(), parsedItem.getFailures().keySet()); for (String queryId : testItem.getFailures().keySet()) { Exception ex = parsedItem.getFailures().get(queryId); - assertThat(ex, instanceOf(BaseOpenSearchException.class)); + assertThat(ex, instanceOf(OpenSearchException.class)); } } diff --git a/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java b/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java index 00228e39d2184..07cd901449a18 100644 --- a/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java +++ b/qa/ccs-unavailable-clusters/src/test/java/org/opensearch/search/CrossClusterSearchUnavailableClusterIT.java @@ -36,7 +36,6 @@ import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.io.entity.StringEntity; import org.apache.lucene.search.TotalHits; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsAction; @@ -296,21 +295,21 @@ public void testSkipUnavailableDependsOnSeeds() throws IOException { private static void assertSearchConnectFailure() { { - BaseOpenSearchException exception = expectThrows(BaseOpenSearchException.class, + OpenSearchException exception = expectThrows(OpenSearchException.class, () -> restHighLevelClient.search(new SearchRequest("index", "remote1:index"), RequestOptions.DEFAULT)); - BaseOpenSearchException rootCause = (BaseOpenSearchException)exception.getRootCause(); + OpenSearchException rootCause = (OpenSearchException)exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("connect_exception")); } { - BaseOpenSearchException exception = expectThrows(BaseOpenSearchException.class, + OpenSearchException exception = expectThrows(OpenSearchException.class, () -> restHighLevelClient.search(new SearchRequest("remote1:index"), RequestOptions.DEFAULT)); - BaseOpenSearchException rootCause = (BaseOpenSearchException)exception.getRootCause(); + OpenSearchException rootCause = (OpenSearchException)exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("connect_exception")); } { - BaseOpenSearchException exception = expectThrows(BaseOpenSearchException.class, + OpenSearchException exception = expectThrows(OpenSearchException.class, () -> restHighLevelClient.search(new SearchRequest("remote1:index").scroll("1m"), RequestOptions.DEFAULT)); - BaseOpenSearchException rootCause = (BaseOpenSearchException)exception.getRootCause(); + OpenSearchException rootCause = (OpenSearchException)exception.getRootCause(); assertThat(rootCause.getMessage(), containsString("connect_exception")); } } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java index 33229ebad464e..67e52529ae86b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/TasksIT.java @@ -32,8 +32,8 @@ package org.opensearch.action.admin.cluster.node.tasks; -import org.opensearch.BaseOpenSearchException; import org.opensearch.ExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.action.ActionFuture; import org.opensearch.action.ActionListener; @@ -769,7 +769,7 @@ public void testTasksWaitForAllTask() throws Exception { .get(); // It should finish quickly and without complaint and list the list tasks themselves - assertThat(response.getNodeFailures(), emptyCollectionOf(BaseOpenSearchException.class)); + assertThat(response.getNodeFailures(), emptyCollectionOf(OpenSearchException.class)); assertThat(response.getTaskFailures(), emptyCollectionOf(TaskOperationFailure.class)); assertThat(response.getTasks().size(), greaterThanOrEqualTo(1)); } diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/AggregationsIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/AggregationsIntegrationIT.java index 60a7da4f4912a..b73b7722f9728 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/AggregationsIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/AggregationsIntegrationIT.java @@ -32,7 +32,7 @@ package org.opensearch.search.aggregations; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -137,7 +137,7 @@ private void runLargeStringAggregationTest(AggregationBuilder aggregation) { exceptionThrown = true; Throwable nestedException = ex.getCause(); assertNotNull(nestedException); - assertTrue(nestedException instanceof BaseOpenSearchException); + assertTrue(nestedException instanceof OpenSearchException); assertNotNull(nestedException.getCause()); assertTrue(nestedException.getCause() instanceof IllegalArgumentException); String actualExceptionMessage = nestedException.getCause().getMessage(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/DateHistogramIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/DateHistogramIT.java index 6f97b8ef40ffe..617c5745c9bba 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/DateHistogramIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/DateHistogramIT.java @@ -31,7 +31,7 @@ package org.opensearch.search.aggregations.bucket; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -650,9 +650,9 @@ public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception { .get(); fail("Expected an exception"); } catch (SearchPhaseExecutionException e) { - BaseOpenSearchException[] rootCauses = e.guessRootCauses(); + OpenSearchException[] rootCauses = e.guessRootCauses(); if (rootCauses.length == 1) { - BaseOpenSearchException rootCause = rootCauses[0]; + OpenSearchException rootCause = rootCauses[0]; if (rootCause instanceof AggregationExecutionException) { AggregationExecutionException aggException = (AggregationExecutionException) rootCause; assertThat(aggException.getMessage(), Matchers.startsWith("Invalid aggregation order path")); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/HistogramIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/HistogramIT.java index e56c2b3c713bd..dae788abe0d10 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/HistogramIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/HistogramIT.java @@ -32,7 +32,7 @@ package org.opensearch.search.aggregations.bucket; import com.carrotsearch.hppc.LongHashSet; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -689,9 +689,9 @@ public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception { .get(); fail("Expected an exception"); } catch (SearchPhaseExecutionException e) { - BaseOpenSearchException[] rootCauses = e.guessRootCauses(); + OpenSearchException[] rootCauses = e.guessRootCauses(); if (rootCauses.length == 1) { - BaseOpenSearchException rootCause = rootCauses[0]; + OpenSearchException rootCause = rootCauses[0]; if (rootCause instanceof AggregationExecutionException) { AggregationExecutionException aggException = (AggregationExecutionException) rootCause; assertThat(aggException.getMessage(), Matchers.startsWith("Invalid aggregation order path")); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/terms/StringTermsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/terms/StringTermsIT.java index 96b256dc81ce1..fa8e823545b36 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/terms/StringTermsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/terms/StringTermsIT.java @@ -31,7 +31,6 @@ package org.opensearch.search.aggregations.bucket.terms; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -421,9 +420,9 @@ public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception { .get(); fail("Expected an exception"); } catch (SearchPhaseExecutionException e) { - BaseOpenSearchException[] rootCauses = e.guessRootCauses(); + OpenSearchException[] rootCauses = e.guessRootCauses(); if (rootCauses.length == 1) { - BaseOpenSearchException rootCause = rootCauses[0]; + OpenSearchException rootCause = rootCauses[0]; if (rootCause instanceof AggregationExecutionException) { AggregationExecutionException aggException = (AggregationExecutionException) rootCause; assertThat(aggException.getMessage(), startsWith("Invalid aggregation order path")); diff --git a/server/src/main/java/org/opensearch/OpenSearchException.java b/server/src/main/java/org/opensearch/OpenSearchServerException.java similarity index 76% rename from server/src/main/java/org/opensearch/OpenSearchException.java rename to server/src/main/java/org/opensearch/OpenSearchServerException.java index 9ee67964ff3cd..dff17ef33aefe 100644 --- a/server/src/main/java/org/opensearch/OpenSearchException.java +++ b/server/src/main/java/org/opensearch/OpenSearchServerException.java @@ -6,49 +6,12 @@ * compatible open source license. */ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - package org.opensearch; -import org.opensearch.action.support.replication.ReplicationOperation; -import org.opensearch.cluster.action.shard.ShardStateAction; -import org.opensearch.cluster.routing.NodeWeighedAwayException; -import org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException; -import org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException; -import org.opensearch.cluster.service.ClusterManagerThrottlingException; -import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.index.snapshots.IndexShardSnapshotException; -import org.opensearch.search.aggregations.MultiBucketConsumerService; -import org.opensearch.search.pipeline.SearchPipelineProcessingException; -import org.opensearch.snapshots.SnapshotInUseDeletionException; -import org.opensearch.transport.TcpTransport; - -import java.io.IOException; -import static org.opensearch.BaseOpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; +import static org.opensearch.OpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; +import static org.opensearch.OpenSearchException.UNKNOWN_VERSION_ADDED; import static org.opensearch.Version.V_2_1_0; import static org.opensearch.Version.V_2_4_0; import static org.opensearch.Version.V_2_5_0; @@ -57,20 +20,24 @@ import static org.opensearch.Version.V_3_0_0; /** - * A base class for all opensearch exceptions. + * Utility class to register server exceptions * * @opensearch.internal */ -public class OpenSearchException extends BaseOpenSearchException { +public final class OpenSearchServerException { + + private OpenSearchServerException() { + // no ctor: + } /** * Setting a higher base exception id to avoid conflicts. */ private static final int CUSTOM_ELASTICSEARCH_EXCEPTIONS_BASE_ID = 10000; - static { + public static void registerExceptions() { registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.dfs.DfsPhaseExecutionException.class, org.opensearch.search.dfs.DfsPhaseExecutionException::new, 1, @@ -78,7 +45,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.common.util.CancellableThreads.ExecutionCancelledException.class, org.opensearch.common.util.CancellableThreads.ExecutionCancelledException::new, 2, @@ -86,7 +53,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.discovery.ClusterManagerNotDiscoveredException.class, org.opensearch.discovery.ClusterManagerNotDiscoveredException::new, 3, @@ -94,7 +61,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.OpenSearchSecurityException.class, org.opensearch.OpenSearchSecurityException::new, 4, @@ -102,7 +69,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardRestoreException.class, org.opensearch.index.snapshots.IndexShardRestoreException::new, 5, @@ -110,7 +77,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.IndexClosedException.class, org.opensearch.indices.IndexClosedException::new, 6, @@ -118,7 +85,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.http.BindHttpException.class, org.opensearch.http.BindHttpException::new, 7, @@ -126,7 +93,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.search.ReduceSearchPhaseException.class, org.opensearch.action.search.ReduceSearchPhaseException::new, 8, @@ -134,7 +101,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.node.NodeClosedException.class, org.opensearch.node.NodeClosedException::new, 9, @@ -142,7 +109,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.SnapshotFailedEngineException.class, org.opensearch.index.engine.SnapshotFailedEngineException::new, 10, @@ -150,7 +117,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.ShardNotFoundException.class, org.opensearch.index.shard.ShardNotFoundException::new, 11, @@ -158,7 +125,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.ConnectTransportException.class, org.opensearch.transport.ConnectTransportException::new, 12, @@ -166,7 +133,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.NotSerializableTransportException.class, org.opensearch.transport.NotSerializableTransportException::new, 13, @@ -174,7 +141,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.ResponseHandlerFailureTransportException.class, org.opensearch.transport.ResponseHandlerFailureTransportException::new, 14, @@ -182,7 +149,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.IndexCreationException.class, org.opensearch.indices.IndexCreationException::new, 15, @@ -190,7 +157,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.IndexNotFoundException.class, org.opensearch.index.IndexNotFoundException::new, 16, @@ -198,7 +165,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.routing.IllegalShardRoutingStateException.class, org.opensearch.cluster.routing.IllegalShardRoutingStateException::new, 17, @@ -206,7 +173,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException.class, org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException::new, 18, @@ -214,7 +181,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.ResourceNotFoundException.class, org.opensearch.ResourceNotFoundException::new, 19, @@ -222,7 +189,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.ActionTransportException.class, org.opensearch.transport.ActionTransportException::new, 20, @@ -230,7 +197,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.OpenSearchGenerationException.class, org.opensearch.OpenSearchGenerationException::new, 21, @@ -239,7 +206,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 22 was CreateFailedEngineException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardStartedException.class, org.opensearch.index.shard.IndexShardStartedException::new, 23, @@ -247,7 +214,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.SearchContextMissingException.class, org.opensearch.search.SearchContextMissingException::new, 24, @@ -255,7 +222,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.script.GeneralScriptException.class, org.opensearch.script.GeneralScriptException::new, 25, @@ -264,7 +231,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 26 was BatchOperationException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotCreationException.class, org.opensearch.snapshots.SnapshotCreationException::new, 27, @@ -273,7 +240,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 28 was DeleteFailedEngineException, deprecated in 6.0, removed in 7.0 registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.DocumentMissingException.class, org.opensearch.index.engine.DocumentMissingException::new, 29, @@ -281,7 +248,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotException.class, org.opensearch.snapshots.SnapshotException::new, 30, @@ -289,7 +256,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.InvalidAliasNameException.class, org.opensearch.indices.InvalidAliasNameException::new, 31, @@ -297,7 +264,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.InvalidIndexNameException.class, org.opensearch.indices.InvalidIndexNameException::new, 32, @@ -305,7 +272,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.IndexPrimaryShardNotAllocatedException.class, org.opensearch.indices.IndexPrimaryShardNotAllocatedException::new, 33, @@ -313,7 +280,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.TransportException.class, org.opensearch.transport.TransportException::new, 34, @@ -321,7 +288,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.OpenSearchParseException.class, org.opensearch.OpenSearchParseException::new, 35, @@ -329,7 +296,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.SearchException.class, org.opensearch.search.SearchException::new, 36, @@ -337,7 +304,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.mapper.MapperException.class, org.opensearch.index.mapper.MapperException::new, 37, @@ -345,7 +312,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.InvalidTypeNameException.class, org.opensearch.indices.InvalidTypeNameException::new, 38, @@ -353,7 +320,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotRestoreException.class, org.opensearch.snapshots.SnapshotRestoreException::new, 39, @@ -361,7 +328,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardClosedException.class, org.opensearch.index.shard.IndexShardClosedException::new, 41, @@ -369,7 +336,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.recovery.RecoverFilesRecoveryException.class, org.opensearch.indices.recovery.RecoverFilesRecoveryException::new, 42, @@ -377,7 +344,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.translog.TruncatedTranslogException.class, org.opensearch.index.translog.TruncatedTranslogException::new, 43, @@ -385,7 +352,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.recovery.RecoveryFailedException.class, org.opensearch.indices.recovery.RecoveryFailedException::new, 44, @@ -393,7 +360,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRelocatedException.class, org.opensearch.index.shard.IndexShardRelocatedException::new, 45, @@ -401,7 +368,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.NodeShouldNotConnectException.class, org.opensearch.transport.NodeShouldNotConnectException::new, 46, @@ -410,7 +377,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 47 used to be for IndexTemplateAlreadyExistsException which was deprecated in 5.1 removed in 6.0 registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.translog.TranslogCorruptedException.class, org.opensearch.index.translog.TranslogCorruptedException::new, 48, @@ -418,7 +385,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.block.ClusterBlockException.class, org.opensearch.cluster.block.ClusterBlockException::new, 49, @@ -426,7 +393,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.fetch.FetchPhaseExecutionException.class, org.opensearch.search.fetch.FetchPhaseExecutionException::new, 50, @@ -435,7 +402,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 51 used to be for IndexShardAlreadyExistsException which was deprecated in 5.1 removed in 6.0 registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.VersionConflictEngineException.class, org.opensearch.index.engine.VersionConflictEngineException::new, 52, @@ -443,7 +410,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.EngineException.class, org.opensearch.index.engine.EngineException::new, 53, @@ -452,7 +419,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 54 was DocumentAlreadyExistsException, which is superseded by VersionConflictEngineException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.NoSuchNodeException.class, org.opensearch.action.NoSuchNodeException::new, 55, @@ -460,7 +427,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.common.settings.SettingsException.class, org.opensearch.common.settings.SettingsException::new, 56, @@ -468,7 +435,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.IndexTemplateMissingException.class, org.opensearch.indices.IndexTemplateMissingException::new, 57, @@ -476,7 +443,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.SendRequestTransportException.class, org.opensearch.transport.SendRequestTransportException::new, 58, @@ -487,7 +454,7 @@ public class OpenSearchException extends BaseOpenSearchException { // 60 used to be for EarlyTerminationException // 61 used to be for RoutingValidationException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.AliasFilterParsingException.class, org.opensearch.indices.AliasFilterParsingException::new, 63, @@ -496,7 +463,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 64 was DeleteByQueryFailedEngineException, which was removed in 5.0 registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.gateway.GatewayException.class, org.opensearch.gateway.GatewayException::new, 65, @@ -504,7 +471,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardNotRecoveringException.class, org.opensearch.index.shard.IndexShardNotRecoveringException::new, 66, @@ -512,7 +479,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.http.HttpException.class, org.opensearch.http.HttpException::new, 67, @@ -520,10 +487,15 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle(OpenSearchException.class, OpenSearchException::new, 68, UNKNOWN_VERSION_ADDED) + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.OpenSearchException.class, + org.opensearch.OpenSearchException::new, + 68, + UNKNOWN_VERSION_ADDED + ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotMissingException.class, org.opensearch.snapshots.SnapshotMissingException::new, 69, @@ -531,7 +503,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.PrimaryMissingActionException.class, org.opensearch.action.PrimaryMissingActionException::new, 70, @@ -539,7 +511,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.SearchParseException.class, org.opensearch.search.SearchParseException::new, 72, @@ -547,7 +519,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.FailedNodeException.class, org.opensearch.action.FailedNodeException::new, 71, @@ -555,7 +527,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.ConcurrentSnapshotExecutionException.class, org.opensearch.snapshots.ConcurrentSnapshotExecutionException::new, 73, @@ -563,7 +535,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.common.blobstore.BlobStoreException.class, org.opensearch.common.blobstore.BlobStoreException::new, 74, @@ -571,7 +543,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.IncompatibleClusterStateVersionException.class, org.opensearch.cluster.IncompatibleClusterStateVersionException::new, 75, @@ -579,7 +551,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.RecoveryEngineException.class, org.opensearch.index.engine.RecoveryEngineException::new, 76, @@ -587,7 +559,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.common.util.concurrent.UncategorizedExecutionException.class, org.opensearch.common.util.concurrent.UncategorizedExecutionException::new, 77, @@ -595,7 +567,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.TimestampParsingException.class, org.opensearch.action.TimestampParsingException::new, 78, @@ -603,7 +575,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.RoutingMissingException.class, org.opensearch.action.RoutingMissingException::new, 79, @@ -612,7 +584,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 80 was IndexFailedEngineException, deprecated in 6.0, removed in 7.0 registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardRestoreFailedException.class, org.opensearch.index.snapshots.IndexShardRestoreFailedException::new, 81, @@ -620,7 +592,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.repositories.RepositoryException.class, org.opensearch.repositories.RepositoryException::new, 82, @@ -628,7 +600,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.ReceiveTimeoutTransportException.class, org.opensearch.transport.ReceiveTimeoutTransportException::new, 83, @@ -636,7 +608,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.NodeDisconnectedException.class, org.opensearch.transport.NodeDisconnectedException::new, 84, @@ -645,7 +617,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 85 used to be for AlreadyExpiredException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.aggregations.AggregationExecutionException.class, org.opensearch.search.aggregations.AggregationExecutionException::new, 86, @@ -654,7 +626,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 87 used to be for MergeMappingException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.InvalidIndexTemplateException.class, org.opensearch.indices.InvalidIndexTemplateException::new, 88, @@ -662,7 +634,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.RefreshFailedEngineException.class, org.opensearch.index.engine.RefreshFailedEngineException::new, 90, @@ -670,7 +642,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.aggregations.AggregationInitializationException.class, org.opensearch.search.aggregations.AggregationInitializationException::new, 91, @@ -678,7 +650,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.recovery.DelayRecoveryException.class, org.opensearch.indices.recovery.DelayRecoveryException::new, 92, @@ -687,7 +659,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 93 used to be for IndexWarmerMissingException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.client.transport.NoNodeAvailableException.class, org.opensearch.client.transport.NoNodeAvailableException::new, 94, @@ -695,7 +667,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.InvalidSnapshotNameException.class, org.opensearch.snapshots.InvalidSnapshotNameException::new, 96, @@ -703,7 +675,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IllegalIndexShardStateException.class, org.opensearch.index.shard.IllegalIndexShardStateException::new, 97, @@ -711,7 +683,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( IndexShardSnapshotException.class, IndexShardSnapshotException::new, 98, @@ -719,7 +691,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardNotStartedException.class, org.opensearch.index.shard.IndexShardNotStartedException::new, 99, @@ -727,7 +699,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.search.SearchPhaseExecutionException.class, org.opensearch.action.search.SearchPhaseExecutionException::new, 100, @@ -735,7 +707,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.ActionNotFoundTransportException.class, org.opensearch.transport.ActionNotFoundTransportException::new, 101, @@ -743,7 +715,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.TransportSerializationException.class, org.opensearch.transport.TransportSerializationException::new, 102, @@ -751,7 +723,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.RemoteTransportException.class, org.opensearch.transport.RemoteTransportException::new, 103, @@ -759,7 +731,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.EngineCreationFailureException.class, org.opensearch.index.engine.EngineCreationFailureException::new, 104, @@ -767,7 +739,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.routing.RoutingException.class, org.opensearch.cluster.routing.RoutingException::new, 105, @@ -775,7 +747,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRecoveryException.class, org.opensearch.index.shard.IndexShardRecoveryException::new, 106, @@ -783,7 +755,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.repositories.RepositoryMissingException.class, org.opensearch.repositories.RepositoryMissingException::new, 107, @@ -791,7 +763,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.DocumentSourceMissingException.class, org.opensearch.index.engine.DocumentSourceMissingException::new, 109, @@ -800,7 +772,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 110 used to be FlushNotAllowedEngineException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.common.settings.NoClassSettingsException.class, org.opensearch.common.settings.NoClassSettingsException::new, 111, @@ -808,7 +780,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.BindTransportException.class, org.opensearch.transport.BindTransportException::new, 112, @@ -816,7 +788,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.rest.action.admin.indices.AliasesNotFoundException.class, org.opensearch.rest.action.admin.indices.AliasesNotFoundException::new, 113, @@ -824,7 +796,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRecoveringException.class, org.opensearch.index.shard.IndexShardRecoveringException::new, 114, @@ -832,7 +804,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.translog.TranslogException.class, org.opensearch.index.translog.TranslogException::new, 115, @@ -840,7 +812,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException.class, org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException::new, 116, @@ -848,15 +820,15 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - ReplicationOperation.RetryOnPrimaryException.class, - ReplicationOperation.RetryOnPrimaryException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.action.support.replication.ReplicationOperation.RetryOnPrimaryException.class, + org.opensearch.action.support.replication.ReplicationOperation.RetryOnPrimaryException::new, 117, UNKNOWN_VERSION_ADDED ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.OpenSearchTimeoutException.class, org.opensearch.OpenSearchTimeoutException::new, 118, @@ -864,7 +836,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.query.QueryPhaseExecutionException.class, org.opensearch.search.query.QueryPhaseExecutionException::new, 119, @@ -872,7 +844,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.repositories.RepositoryVerificationException.class, org.opensearch.repositories.RepositoryVerificationException::new, 120, @@ -880,7 +852,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.aggregations.InvalidAggregationPathException.class, org.opensearch.search.aggregations.InvalidAggregationPathException::new, 121, @@ -889,7 +861,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 123 used to be IndexAlreadyExistsException and was renamed registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( ResourceAlreadyExistsException.class, ResourceAlreadyExistsException::new, 123, @@ -898,15 +870,15 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 124 used to be Script.ScriptParseException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - TcpTransport.HttpRequestOnTransportException.class, - TcpTransport.HttpRequestOnTransportException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.transport.TcpTransport.HttpRequestOnTransportException.class, + org.opensearch.transport.TcpTransport.HttpRequestOnTransportException::new, 125, UNKNOWN_VERSION_ADDED ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.mapper.MapperParsingException.class, org.opensearch.index.mapper.MapperParsingException::new, 126, @@ -915,7 +887,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 127 used to be org.opensearch.search.SearchContextException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.search.builder.SearchSourceBuilderException.class, org.opensearch.search.builder.SearchSourceBuilderException::new, 128, @@ -924,7 +896,7 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 129 was EngineClosedException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.NoShardAvailableActionException.class, org.opensearch.action.NoShardAvailableActionException::new, 130, @@ -932,7 +904,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.UnavailableShardsException.class, org.opensearch.action.UnavailableShardsException::new, 131, @@ -940,7 +912,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.engine.FlushFailedEngineException.class, org.opensearch.index.engine.FlushFailedEngineException::new, 132, @@ -948,7 +920,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.common.breaker.CircuitBreakingException.class, org.opensearch.common.breaker.CircuitBreakingException::new, 133, @@ -956,7 +928,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.NodeNotConnectedException.class, org.opensearch.transport.NodeNotConnectedException::new, 134, @@ -964,7 +936,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.mapper.StrictDynamicMappingException.class, org.opensearch.index.mapper.StrictDynamicMappingException::new, 135, @@ -972,7 +944,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException.class, org.opensearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException::new, 136, @@ -980,7 +952,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.TypeMissingException.class, org.opensearch.indices.TypeMissingException::new, 137, @@ -988,7 +960,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.coordination.FailedToCommitClusterStateException.class, org.opensearch.cluster.coordination.FailedToCommitClusterStateException::new, 140, @@ -996,7 +968,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.query.QueryShardException.class, org.opensearch.index.query.QueryShardException::new, 141, @@ -1004,15 +976,15 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - ShardStateAction.NoLongerPrimaryShardException.class, - ShardStateAction.NoLongerPrimaryShardException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.cluster.action.shard.ShardStateAction.NoLongerPrimaryShardException.class, + org.opensearch.cluster.action.shard.ShardStateAction.NoLongerPrimaryShardException::new, 142, UNKNOWN_VERSION_ADDED ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.script.ScriptException.class, org.opensearch.script.ScriptException::new, 143, @@ -1020,7 +992,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.NotClusterManagerException.class, org.opensearch.cluster.NotClusterManagerException::new, 144, @@ -1028,7 +1000,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.OpenSearchStatusException.class, org.opensearch.OpenSearchStatusException::new, 145, @@ -1036,7 +1008,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.tasks.TaskCancelledException.class, org.opensearch.tasks.TaskCancelledException::new, 146, @@ -1044,7 +1016,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.env.ShardLockObtainFailedException.class, org.opensearch.env.ShardLockObtainFailedException::new, 147, @@ -1053,15 +1025,15 @@ public class OpenSearchException extends BaseOpenSearchException { ); // 148 was UnknownNamedObjectException registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - MultiBucketConsumerService.TooManyBucketsException.class, - MultiBucketConsumerService.TooManyBucketsException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.search.aggregations.MultiBucketConsumerService.TooManyBucketsException.class, + org.opensearch.search.aggregations.MultiBucketConsumerService.TooManyBucketsException::new, 149, UNKNOWN_VERSION_ADDED ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.coordination.CoordinationStateRejectedException.class, org.opensearch.cluster.coordination.CoordinationStateRejectedException::new, 150, @@ -1069,7 +1041,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotInProgressException.class, org.opensearch.snapshots.SnapshotInProgressException::new, 151, @@ -1077,7 +1049,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.NoSuchRemoteClusterException.class, org.opensearch.transport.NoSuchRemoteClusterException::new, 152, @@ -1085,7 +1057,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException.class, org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException::new, 153, @@ -1093,7 +1065,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseNotFoundException.class, org.opensearch.index.seqno.RetentionLeaseNotFoundException::new, 154, @@ -1101,7 +1073,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.ShardNotInPrimaryModeException.class, org.opensearch.index.shard.ShardNotInPrimaryModeException::new, 155, @@ -1109,7 +1081,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException.class, org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException::new, 156, @@ -1117,7 +1089,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.ingest.IngestProcessorException.class, org.opensearch.ingest.IngestProcessorException::new, 157, @@ -1125,7 +1097,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.recovery.PeerRecoveryNotFound.class, org.opensearch.indices.recovery.PeerRecoveryNotFound::new, 158, @@ -1133,7 +1105,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.coordination.NodeHealthCheckFailureException.class, org.opensearch.cluster.coordination.NodeHealthCheckFailureException::new, 159, @@ -1141,7 +1113,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.transport.NoSeedNodeLeftException.class, org.opensearch.transport.NoSeedNodeLeftException::new, 160, @@ -1149,7 +1121,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.indices.replication.common.ReplicationFailedException.class, org.opensearch.indices.replication.common.ReplicationFailedException::new, 161, @@ -1157,7 +1129,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.index.shard.PrimaryShardClosedException.class, org.opensearch.index.shard.PrimaryShardClosedException::new, 162, @@ -1165,7 +1137,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.decommission.DecommissioningFailedException.class, org.opensearch.cluster.decommission.DecommissioningFailedException::new, 163, @@ -1173,7 +1145,7 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.decommission.NodeDecommissionedException.class, org.opensearch.cluster.decommission.NodeDecommissionedException::new, 164, @@ -1181,45 +1153,55 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - ClusterManagerThrottlingException.class, - ClusterManagerThrottlingException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.cluster.service.ClusterManagerThrottlingException.class, + org.opensearch.cluster.service.ClusterManagerThrottlingException::new, 165, Version.V_2_5_0 ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - SnapshotInUseDeletionException.class, - SnapshotInUseDeletionException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.snapshots.SnapshotInUseDeletionException.class, + org.opensearch.snapshots.SnapshotInUseDeletionException::new, 166, UNKNOWN_VERSION_ADDED ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - UnsupportedWeightedRoutingStateException.class, - UnsupportedWeightedRoutingStateException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException.class, + org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException::new, 167, V_2_5_0 ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( - PreferenceBasedSearchNotAllowedException.class, - PreferenceBasedSearchNotAllowedException::new, + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException.class, + org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException::new, 168, V_2_6_0 ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle(NodeWeighedAwayException.class, NodeWeighedAwayException::new, 169, V_2_6_0) + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.cluster.routing.NodeWeighedAwayException.class, + org.opensearch.cluster.routing.NodeWeighedAwayException::new, + 169, + V_2_6_0 + ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle(SearchPipelineProcessingException.class, SearchPipelineProcessingException::new, 170, V_2_7_0) + new OpenSearchException.OpenSearchExceptionHandle( + org.opensearch.search.pipeline.SearchPipelineProcessingException.class, + org.opensearch.search.pipeline.SearchPipelineProcessingException::new, + 170, + V_2_7_0 + ) ); registerExceptionHandle( - new BaseOpenSearchExceptionHandle( + new OpenSearchException.OpenSearchExceptionHandle( org.opensearch.cluster.block.IndexCreateBlockException.class, org.opensearch.cluster.block.IndexCreateBlockException::new, CUSTOM_ELASTICSEARCH_EXCEPTIONS_BASE_ID + 1, @@ -1227,57 +1209,4 @@ public class OpenSearchException extends BaseOpenSearchException { ) ); } - - /** - * Construct a OpenSearchException with the specified cause exception. - */ - public OpenSearchException(Throwable cause) { - super(cause); - } - - /** - * Construct a OpenSearchException with the specified detail message. - * - * The message can be parameterized using {} as placeholders for the given - * arguments - * - * @param msg the detail message - * @param args the arguments for the message - */ - public OpenSearchException(String msg, Object... args) { - super(msg, args); - } - - /** - * Construct a OpenSearchException with the specified detail message - * and nested exception. - * - * The message can be parameterized using {} as placeholders for the given - * arguments - * - * @param msg the detail message - * @param cause the nested exception - * @param args the arguments for the message - */ - public OpenSearchException(String msg, Throwable cause, Object... args) { - super(msg, cause, args); - } - - public OpenSearchException(StreamInput in) throws IOException { - super(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - } - - /** - * Returns true iff the given class is a registered for an exception to be read. - * - * note: this "override" method is provided to ensure static registration of the exceptions above - */ - public static boolean isRegistered(final Class exception, Version version) { - return BaseOpenSearchException.isRegistered(exception, version); - } } diff --git a/server/src/main/java/org/opensearch/action/TaskOperationFailure.java b/server/src/main/java/org/opensearch/action/TaskOperationFailure.java index 41b4203201575..ea6f5508ab332 100644 --- a/server/src/main/java/org/opensearch/action/TaskOperationFailure.java +++ b/server/src/main/java/org/opensearch/action/TaskOperationFailure.java @@ -33,7 +33,6 @@ package org.opensearch.action; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -76,7 +75,7 @@ public final class TaskOperationFailure implements Writeable, ToXContentFragment int i = 0; String nodeId = (String) constructorObjects[i++]; long taskId = (long) constructorObjects[i++]; - BaseOpenSearchException reason = (BaseOpenSearchException) constructorObjects[i]; + OpenSearchException reason = (OpenSearchException) constructorObjects[i]; return new TaskOperationFailure(nodeId, taskId, reason); } ); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java index b7b589606561b..b806e78cd93ff 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java @@ -31,7 +31,7 @@ package org.opensearch.action.admin.indices.close; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.DefaultShardOperationFailedException; import org.opensearch.action.support.master.ShardsAcknowledgedResponse; import org.opensearch.common.Nullable; @@ -172,7 +172,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa builder.field("closed", false); if (exception != null) { builder.startObject("exception"); - BaseOpenSearchException.generateFailureXContent(builder, params, exception, true); + OpenSearchException.generateFailureXContent(builder, params, exception, true); builder.endObject(); } else { builder.startObject("failedShards"); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java index 6d31dfb98b7c8..6d89170fefd7c 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java @@ -31,7 +31,7 @@ package org.opensearch.action.admin.indices.readonly; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.DefaultShardOperationFailedException; import org.opensearch.action.support.master.ShardsAcknowledgedResponse; import org.opensearch.common.Nullable; @@ -172,7 +172,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa if (hasFailures()) { if (exception != null) { builder.startObject("exception"); - BaseOpenSearchException.generateFailureXContent(builder, params, exception, true); + OpenSearchException.generateFailureXContent(builder, params, exception, true); builder.endObject(); } else { builder.startArray("failed_shards"); diff --git a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java index 705561e7c90e4..f5e8967d81c53 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java @@ -33,7 +33,6 @@ package org.opensearch.action.bulk; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.DocWriteRequest.OpType; @@ -144,7 +143,7 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw } RestStatus status = null; - BaseOpenSearchException exception = null; + OpenSearchException exception = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); @@ -152,7 +151,7 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw if (ERROR.equals(currentFieldName)) { if (token == XContentParser.Token.START_OBJECT) { - exception = BaseOpenSearchException.fromXContent(parser); + exception = OpenSearchException.fromXContent(parser); } } else if (STATUS.equals(currentFieldName)) { if (token == XContentParser.Token.VALUE_NUMBER) { diff --git a/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java b/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java index 439a6694bde7f..88f78d2ca6815 100644 --- a/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java +++ b/server/src/main/java/org/opensearch/action/get/MultiGetResponse.java @@ -32,7 +32,7 @@ package org.opensearch.action.get; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.ActionResponse; import org.opensearch.common.io.stream.StreamInput; @@ -130,7 +130,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); builder.field(INDEX.getPreferredName(), index); builder.field(ID.getPreferredName(), id); - BaseOpenSearchException.generateFailureXContent(builder, params, exception, true); + OpenSearchException.generateFailureXContent(builder, params, exception, true); builder.endObject(); return builder; } @@ -208,7 +208,7 @@ private static MultiGetItemResponse parseItem(XContentParser parser) throws IOEx String currentFieldName = null; String index = null; String id = null; - BaseOpenSearchException exception = null; + OpenSearchException exception = null; GetResult getResult = null; for (Token token = parser.nextToken(); token != Token.END_OBJECT; token = parser.nextToken()) { switch (token) { @@ -230,7 +230,7 @@ private static MultiGetItemResponse parseItem(XContentParser parser) throws IOEx break; case START_OBJECT: if (ERROR.match(currentFieldName, parser.getDeprecationHandler())) { - exception = BaseOpenSearchException.fromXContent(parser); + exception = OpenSearchException.fromXContent(parser); } break; default: diff --git a/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java b/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java index 26222d0d9730e..db88214cff0ec 100644 --- a/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java +++ b/server/src/main/java/org/opensearch/action/ingest/SimulateDocumentBaseResult.java @@ -31,7 +31,6 @@ package org.opensearch.action.ingest; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -63,7 +62,7 @@ public final class SimulateDocumentBaseResult implements SimulateDocumentResult return new SimulateDocumentBaseResult(((WriteableIngestDocument) a[0]).getIngestDocument()); } else { assert a[0] == null; - return new SimulateDocumentBaseResult((BaseOpenSearchException) a[1]); + return new SimulateDocumentBaseResult((OpenSearchException) a[1]); } } ); @@ -126,7 +125,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (failure == null) { ingestDocument.toXContent(builder, params); } else { - BaseOpenSearchException.generateFailureXContent(builder, params, failure, true); + OpenSearchException.generateFailureXContent(builder, params, failure, true); } builder.endObject(); return builder; diff --git a/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java b/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java index a089f40990b7f..509705fe856e8 100644 --- a/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java +++ b/server/src/main/java/org/opensearch/action/ingest/SimulateProcessorResult.java @@ -31,7 +31,6 @@ package org.opensearch.action.ingest; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.core.ParseField; import org.opensearch.common.collect.Tuple; @@ -88,10 +87,10 @@ public static Status fromString(String string) { private final Exception failure; private final Tuple conditionalWithResult; - private static final ConstructingObjectParser IGNORED_ERROR_PARSER = new ConstructingObjectParser<>( + private static final ConstructingObjectParser IGNORED_ERROR_PARSER = new ConstructingObjectParser<>( "ignored_error_parser", true, - a -> (BaseOpenSearchException) a[0] + a -> (OpenSearchException) a[0] ); static { IGNORED_ERROR_PARSER.declareObject(constructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField("error")); @@ -123,9 +122,9 @@ public static Status fromString(String string) { IngestDocument document = a[4] == null ? null : ((WriteableIngestDocument) a[4]).getIngestDocument(); Exception failure = null; if (a[5] != null) { - failure = (BaseOpenSearchException) a[5]; + failure = (OpenSearchException) a[5]; } else if (a[6] != null) { - failure = (BaseOpenSearchException) a[6]; + failure = (OpenSearchException) a[6]; } return new SimulateProcessorResult(type, processorTag, description, document, failure, conditionalWithResult); @@ -270,10 +269,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (failure != null && ingestDocument != null) { builder.startObject(IGNORED_ERROR_FIELD); - BaseOpenSearchException.generateFailureXContent(builder, params, failure, true); + OpenSearchException.generateFailureXContent(builder, params, failure, true); builder.endObject(); } else if (failure != null) { - BaseOpenSearchException.generateFailureXContent(builder, params, failure, true); + OpenSearchException.generateFailureXContent(builder, params, failure, true); } if (ingestDocument != null) { diff --git a/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java b/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java index 89869582910e5..969e0edbbc9d6 100644 --- a/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java +++ b/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java @@ -34,8 +34,8 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.opensearch.BaseOpenSearchException; import org.opensearch.ExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.NoShardAvailableActionException; @@ -367,7 +367,7 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha final ShardOperationFailedException[] shardSearchFailures = ExceptionsHelper.groupBy(buildShardFailures()); Throwable cause = shardSearchFailures.length == 0 ? null - : BaseOpenSearchException.guessRootCauses(shardSearchFailures[0].getCause())[0]; + : OpenSearchException.guessRootCauses(shardSearchFailures[0].getCause())[0]; logger.debug(() -> new ParameterizedMessage("All shards failed for phase: [{}]", getName()), cause); onPhaseFailure(currentPhase, "all shards failed", cause); } else { @@ -381,7 +381,7 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha if (logger.isDebugEnabled()) { int numShardFailures = shardSearchFailures.length; shardSearchFailures = ExceptionsHelper.groupBy(shardSearchFailures); - Throwable cause = BaseOpenSearchException.guessRootCauses(shardSearchFailures[0].getCause())[0]; + Throwable cause = OpenSearchException.guessRootCauses(shardSearchFailures[0].getCause())[0]; logger.debug( () -> new ParameterizedMessage("{} shards failed for phase: [{}]", numShardFailures, getName()), cause diff --git a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java index 43efa575b9110..c00eb572b6ac4 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java @@ -33,7 +33,6 @@ package org.opensearch.action.search; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.common.Nullable; @@ -192,7 +191,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws for (Item item : items) { builder.startObject(); if (item.isFailure()) { - BaseOpenSearchException.generateFailureXContent(builder, params, item.getFailure(), true); + OpenSearchException.generateFailureXContent(builder, params, item.getFailure(), true); builder.field(Fields.STATUS, BaseExceptionsHelper.status(item.getFailure()).getStatus()); } else { item.getResponse().innerToXContent(builder, params); diff --git a/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java b/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java index 82429a1c2254f..aead19afc2942 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java +++ b/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java @@ -33,7 +33,6 @@ package org.opensearch.action.search; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ShardOperationFailedException; @@ -123,7 +122,7 @@ public Throwable getCause() { Throwable cause = super.getCause(); if (cause == null) { // fall back to guessed root cause - for (BaseOpenSearchException rootCause : guessRootCauses()) { + for (OpenSearchException rootCause : guessRootCauses()) { return rootCause; } } @@ -183,14 +182,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } @Override - public BaseOpenSearchException[] guessRootCauses() { + public OpenSearchException[] guessRootCauses() { ShardOperationFailedException[] failures = ExceptionsHelper.groupBy(shardFailures); - List rootCauses = new ArrayList<>(failures.length); + List rootCauses = new ArrayList<>(failures.length); for (ShardOperationFailedException failure : failures) { - BaseOpenSearchException[] guessRootCauses = BaseOpenSearchException.guessRootCauses(failure.getCause()); + OpenSearchException[] guessRootCauses = OpenSearchException.guessRootCauses(failure.getCause()); rootCauses.addAll(Arrays.asList(guessRootCauses)); } - return rootCauses.toArray(new BaseOpenSearchException[0]); + return rootCauses.toArray(new OpenSearchException[0]); } @Override diff --git a/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java b/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java index 80465a75da764..aafdd553d4522 100644 --- a/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java +++ b/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java @@ -33,7 +33,7 @@ package org.opensearch.action.search; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.cluster.metadata.IndexMetadata; @@ -162,7 +162,7 @@ public static ShardSearchFailure fromXContent(XContentParser parser) throws IOEx String indexName = null; String clusterAlias = null; String nodeId = null; - BaseOpenSearchException exception = null; + OpenSearchException exception = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); @@ -183,7 +183,7 @@ public static ShardSearchFailure fromXContent(XContentParser parser) throws IOEx } } else if (token == XContentParser.Token.START_OBJECT) { if (REASON_FIELD.equals(currentFieldName)) { - exception = BaseOpenSearchException.fromXContent(parser); + exception = OpenSearchException.fromXContent(parser); } else { parser.skipChildren(); } diff --git a/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java b/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java index a2be1bd7cd12a..1b3b72d45b5b5 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java +++ b/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java @@ -33,7 +33,7 @@ package org.opensearch.action.support.replication; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.cluster.metadata.IndexMetadata; @@ -320,7 +320,7 @@ public static Failure fromXContent(XContentParser parser) throws IOException { int shardId = -1; boolean primary = false; RestStatus status = null; - BaseOpenSearchException reason = null; + OpenSearchException reason = null; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -340,7 +340,7 @@ public static Failure fromXContent(XContentParser parser) throws IOException { } } else if (token == XContentParser.Token.START_OBJECT) { if (REASON.equals(currentFieldName)) { - reason = BaseOpenSearchException.fromXContent(parser); + reason = OpenSearchException.fromXContent(parser); } else { parser.skipChildren(); // skip potential inner objects for forward compatibility } diff --git a/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java b/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java index 8621598aea0f1..fd90f9b389819 100644 --- a/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java +++ b/server/src/main/java/org/opensearch/action/support/tasks/BaseTasksResponse.java @@ -32,7 +32,6 @@ package org.opensearch.action.support.tasks; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.FailedNodeException; @@ -63,7 +62,7 @@ public class BaseTasksResponse extends ActionResponse { protected static final String NODE_FAILURES = "node_failures"; private List taskFailures; - private List nodeFailures; + private List nodeFailures; public BaseTasksResponse(List taskFailures, List nodeFailures) { this.taskFailures = taskFailures == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(taskFailures)); @@ -93,7 +92,7 @@ public void writeTo(StreamOutput out) throws IOException { exp.writeTo(out); } out.writeVInt(nodeFailures.size()); - for (BaseOpenSearchException exp : nodeFailures) { + for (OpenSearchException exp : nodeFailures) { exp.writeTo(out); } } @@ -108,7 +107,7 @@ public List getTaskFailures() { /** * The list of node failures exception. */ - public List getNodeFailures() { + public List getNodeFailures() { return nodeFailures; } @@ -145,7 +144,7 @@ protected void toXContentCommon(XContentBuilder builder, ToXContent.Params param if (getNodeFailures() != null && getNodeFailures().size() > 0) { builder.startArray(NODE_FAILURES); - for (BaseOpenSearchException ex : getNodeFailures()) { + for (OpenSearchException ex : getNodeFailures()) { builder.startObject(); ex.toXContent(builder, params); builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsResponse.java b/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsResponse.java index f1e05592731a5..ff84ceb22e043 100644 --- a/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsResponse.java +++ b/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsResponse.java @@ -32,7 +32,7 @@ package org.opensearch.action.termvectors; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.ActionResponse; import org.opensearch.common.io.stream.StreamInput; @@ -141,7 +141,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws Failure failure = response.getFailure(); builder.field(Fields._INDEX, failure.getIndex()); builder.field(Fields._ID, failure.getId()); - BaseOpenSearchException.generateFailureXContent(builder, params, failure.getCause(), true); + OpenSearchException.generateFailureXContent(builder, params, failure.getCause(), true); builder.endObject(); } else { TermVectorsResponse getResponse = response.getResponse(); diff --git a/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java b/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java index b2919bf23543f..9060487f6364f 100644 --- a/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java +++ b/server/src/main/java/org/opensearch/index/reindex/BulkByScrollResponse.java @@ -32,7 +32,7 @@ package org.opensearch.index.reindex; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchParseException; import org.opensearch.action.ActionResponse; import org.opensearch.action.bulk.BulkItemResponse.Failure; @@ -246,8 +246,8 @@ private static Object parseFailure(XContentParser parser) throws IOException { Integer status = null; Integer shardId = null; String nodeId = null; - BaseOpenSearchException bulkExc = null; - BaseOpenSearchException searchExc = null; + OpenSearchException bulkExc = null; + OpenSearchException searchExc = null; while ((token = parser.nextToken()) != Token.END_OBJECT) { ensureExpectedToken(Token.FIELD_NAME, token, parser); String name = parser.currentName(); @@ -257,10 +257,10 @@ private static Object parseFailure(XContentParser parser) throws IOException { } else if (token == Token.START_OBJECT) { switch (name) { case SearchFailure.REASON_FIELD: - searchExc = BaseOpenSearchException.fromXContent(parser); + searchExc = OpenSearchException.fromXContent(parser); break; case Failure.CAUSE_FIELD: - bulkExc = BaseOpenSearchException.fromXContent(parser); + bulkExc = OpenSearchException.fromXContent(parser); break; default: parser.skipChildren(); diff --git a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java index f3a9b7a4ee92e..c1fa6715a64b6 100644 --- a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java +++ b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java @@ -37,7 +37,6 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchStatusException; import org.opensearch.common.bytes.BytesArray; @@ -173,7 +172,7 @@ protected boolean skipStackTrace() { private void build(XContentBuilder builder, ToXContent.Params params, RestStatus status, boolean detailedErrorsEnabled, Exception e) throws IOException { builder.startObject(); - BaseOpenSearchException.generateFailureXContent(builder, params, e, detailedErrorsEnabled); + OpenSearchException.generateFailureXContent(builder, params, e, detailedErrorsEnabled); builder.field(STATUS, status.getStatus()); builder.endObject(); } @@ -189,7 +188,7 @@ public static OpenSearchStatusException errorFromXContent(XContentParser parser) XContentParser.Token token = parser.nextToken(); ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); - BaseOpenSearchException exception = null; + OpenSearchException exception = null; RestStatus status = null; String currentFieldName = null; @@ -203,7 +202,7 @@ public static OpenSearchStatusException errorFromXContent(XContentParser parser) status = RestStatus.fromCode(parser.intValue()); } } else { - exception = BaseOpenSearchException.failureFromXContent(parser); + exception = OpenSearchException.failureFromXContent(parser); } } diff --git a/server/src/main/java/org/opensearch/transport/TransportService.java b/server/src/main/java/org/opensearch/transport/TransportService.java index cb324035bcd62..f41112d69196b 100644 --- a/server/src/main/java/org/opensearch/transport/TransportService.java +++ b/server/src/main/java/org/opensearch/transport/TransportService.java @@ -35,6 +35,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; +import org.opensearch.OpenSearchServerException; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.ActionListenerResponseHandler; @@ -168,6 +169,7 @@ public void close() {} * over the {@link StreamOutput} and {@link StreamInput} wire */ Streamables.registerStreamables(); + OpenSearchServerException.registerExceptions(); } /** does nothing. easy way to ensure class is loaded so the above static block is called to register the streamables */ diff --git a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java index c296c9e94a568..8b0d6faeb1e61 100644 --- a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java @@ -161,7 +161,8 @@ public void testExceptionRegistration() throws ClassNotFoundException, IOExcepti final Set> hasDedicatedWrite = new HashSet<>(); final Set> registered = new HashSet<>(); final String path = "/org/opensearch"; - final Path startPath = PathUtils.get(OpenSearchException.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + final Path coreLibStartPath = PathUtils.get(OpenSearchException.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + final Path startPath = PathUtils.get(OpenSearchServerException.class.getProtectionDomain().getCodeSource().getLocation().toURI()) .resolve("org") .resolve("opensearch"); final Set ignore = Sets.newHashSet( @@ -243,6 +244,9 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx } }; + // walk the core library start path + Files.walkFileTree(coreLibStartPath, visitor); + // walk the server module start path Files.walkFileTree(startPath, visitor); final Path testStartPath = PathUtils.get(ExceptionSerializationTests.class.getResource(path).toURI()); Files.walkFileTree(testStartPath, visitor); @@ -579,7 +583,7 @@ public void testUnknownException() throws IOException { final Exception ex = new UnknownException("eggplant", parsingException); Exception exception = serialize(ex); assertEquals("unknown_exception: eggplant", exception.getMessage()); - assertTrue(exception instanceof BaseOpenSearchException); + assertTrue(exception instanceof OpenSearchException); ParsingException e = (ParsingException) exception.getCause(); assertEquals(parsingException.getIndex(), e.getIndex()); assertEquals(parsingException.getMessage(), e.getMessage()); @@ -652,7 +656,7 @@ public void testWithRestHeadersException() throws IOException { uhe.addHeader("foo", "foo", "bar"); uhe.addMetadata("opensearch.foo_metadata", "value1", "value2"); - BaseOpenSearchException serialize = serialize((OpenSearchException) uhe); + OpenSearchException serialize = serialize((OpenSearchException) uhe); assertTrue(serialize instanceof NotSerializableExceptionWrapper); NotSerializableExceptionWrapper e = (NotSerializableExceptionWrapper) serialize; assertEquals("unknown_header_exception: msg", e.getMessage()); @@ -715,7 +719,7 @@ public void testThatIdsAreUnique() { } public void testIds() { - Map> ids = new HashMap<>(); + Map> ids = new HashMap<>(); ids.put(0, org.opensearch.index.snapshots.IndexShardSnapshotFailedException.class); ids.put(1, org.opensearch.search.dfs.DfsPhaseExecutionException.class); ids.put(2, org.opensearch.common.util.CancellableThreads.ExecutionCancelledException.class); @@ -886,14 +890,14 @@ public void testIds() { ids.put(170, SearchPipelineProcessingException.class); ids.put(10001, IndexCreateBlockException.class); - Map, Integer> reverse = new HashMap<>(); - for (Map.Entry> entry : ids.entrySet()) { + Map, Integer> reverse = new HashMap<>(); + for (Map.Entry> entry : ids.entrySet()) { if (entry.getValue() != null) { reverse.put(entry.getValue(), entry.getKey()); } } - for (final Tuple> tuple : OpenSearchException.classes()) { + for (final Tuple> tuple : OpenSearchException.classes()) { assertNotNull(tuple.v1()); assertNotNull( tuple.v2().getName() + " not found in ExceptionSerializationTests.testIds. Please add it.", @@ -902,7 +906,7 @@ public void testIds() { assertEquals((int) reverse.get(tuple.v2()), (int) tuple.v1()); } - for (Map.Entry> entry : ids.entrySet()) { + for (Map.Entry> entry : ids.entrySet()) { if (entry.getValue() != null) { assertEquals((int) entry.getKey(), OpenSearchException.getId(entry.getValue())); } diff --git a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java index 73095328fd063..e96fd8b203e3e 100644 --- a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java +++ b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java @@ -128,7 +128,7 @@ public void testGuessRootCause() { "foo", new OpenSearchException("bar", new IndexNotFoundException("foo", new RuntimeException("foobar"))) ); - BaseOpenSearchException[] rootCauses = exception.guessRootCauses(); + OpenSearchException[] rootCauses = exception.guessRootCauses(); assertEquals(rootCauses.length, 1); assertEquals(BaseExceptionsHelper.getExceptionName(rootCauses[0]), "index_not_found_exception"); assertEquals("no such index [foo]", rootCauses[0].getMessage()); @@ -148,7 +148,7 @@ public void testGuessRootCause() { if (randomBoolean()) { rootCauses = (randomBoolean() ? new RemoteTransportException("remoteboom", ex) : ex).guessRootCauses(); } else { - rootCauses = BaseOpenSearchException.guessRootCauses(randomBoolean() ? new RemoteTransportException("remoteboom", ex) : ex); + rootCauses = OpenSearchException.guessRootCauses(randomBoolean() ? new RemoteTransportException("remoteboom", ex) : ex); } assertEquals("parsing_exception", BaseExceptionsHelper.getExceptionName(rootCauses[0])); assertEquals("foobar", rootCauses[0].getMessage()); @@ -176,7 +176,7 @@ public void testGuessRootCause() { "all shards failed", new ShardSearchFailure[] { failure, failure1, failure2 } ); - final BaseOpenSearchException[] rootCauses = ex.guessRootCauses(); + final OpenSearchException[] rootCauses = ex.guessRootCauses(); assertEquals(rootCauses.length, 2); assertEquals(BaseExceptionsHelper.getExceptionName(rootCauses[0]), "parsing_exception"); assertEquals(rootCauses[0].getMessage(), "foobar"); @@ -188,20 +188,20 @@ public void testGuessRootCause() { } { - final BaseOpenSearchException[] foobars = BaseOpenSearchException.guessRootCauses(new IllegalArgumentException("foobar")); + final OpenSearchException[] foobars = OpenSearchException.guessRootCauses(new IllegalArgumentException("foobar")); assertEquals(foobars.length, 1); - assertThat(foobars[0], instanceOf(BaseOpenSearchException.class)); + assertThat(foobars[0], instanceOf(OpenSearchException.class)); assertEquals("foobar", foobars[0].getMessage()); assertEquals(IllegalArgumentException.class, foobars[0].getCause().getClass()); assertEquals("illegal_argument_exception", foobars[0].getExceptionName()); } { - final BaseOpenSearchException[] foobars = BaseOpenSearchException.guessRootCauses( + final OpenSearchException[] foobars = OpenSearchException.guessRootCauses( new RemoteTransportException("abc", new IllegalArgumentException("foobar")) ); assertEquals(foobars.length, 1); - assertThat(foobars[0], instanceOf(BaseOpenSearchException.class)); + assertThat(foobars[0], instanceOf(OpenSearchException.class)); assertEquals("foobar", foobars[0].getMessage()); assertEquals(IllegalArgumentException.class, foobars[0].getCause().getClass()); assertEquals("illegal_argument_exception", foobars[0].getExceptionName()); @@ -210,9 +210,9 @@ public void testGuessRootCause() { { XContentParseException inner = new XContentParseException(null, "inner"); XContentParseException outer = new XContentParseException(null, "outer", inner); - final BaseOpenSearchException[] causes = BaseOpenSearchException.guessRootCauses(outer); + final OpenSearchException[] causes = OpenSearchException.guessRootCauses(outer); assertEquals(causes.length, 1); - assertThat(causes[0], instanceOf(BaseOpenSearchException.class)); + assertThat(causes[0], instanceOf(OpenSearchException.class)); assertEquals("inner", causes[0].getMessage()); assertEquals("x_content_parse_exception", causes[0].getExceptionName()); } @@ -220,9 +220,9 @@ public void testGuessRootCause() { { OpenSearchException inner = new OpenSearchException("inner"); XContentParseException outer = new XContentParseException(null, "outer", inner); - final BaseOpenSearchException[] causes = BaseOpenSearchException.guessRootCauses(outer); + final OpenSearchException[] causes = OpenSearchException.guessRootCauses(outer); assertEquals(causes.length, 1); - assertThat(causes[0], instanceOf(BaseOpenSearchException.class)); + assertThat(causes[0], instanceOf(OpenSearchException.class)); assertEquals("inner", causes[0].getMessage()); assertEquals("exception", causes[0].getExceptionName()); } @@ -515,10 +515,10 @@ public void testToXContentWithHeadersAndMetadata() throws IOException { assertExceptionAsJson(e, expectedJson); - BaseOpenSearchException parsed; + OpenSearchException parsed; try (XContentParser parser = createParser(XContentType.JSON.xContent(), expectedJson)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = BaseOpenSearchException.fromXContent(parser); + parsed = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -532,13 +532,13 @@ public void testToXContentWithHeadersAndMetadata() throws IOException { assertEquals(parsed.getMetadata("opensearch.metadata_foo_0").get(0), "foo_0"); assertEquals(parsed.getMetadata("opensearch.metadata_foo_1").get(0), "foo_1"); - BaseOpenSearchException cause = (BaseOpenSearchException) parsed.getCause(); + OpenSearchException cause = (OpenSearchException) parsed.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=bar]"); - cause = (BaseOpenSearchException) cause.getCause(); + cause = (OpenSearchException) cause.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=baz]"); - cause = (BaseOpenSearchException) cause.getCause(); + cause = (OpenSearchException) cause.getCause(); assertEquals( cause.getMessage(), "OpenSearch exception [type=cluster_block_exception, reason=blocked by: [SERVICE_UNAVAILABLE/2/no cluster-manager];]" @@ -555,10 +555,10 @@ public void testFromXContent() throws IOException { .endObject(); builder = shuffleXContent(builder); - BaseOpenSearchException parsed; + OpenSearchException parsed; try (XContentParser parser = createParser(xContent, BytesReferenceUtil.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = BaseOpenSearchException.fromXContent(parser); + parsed = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -577,10 +577,10 @@ public void testFromXContentWithCause() throws IOException { XContentBuilder builder = XContentBuilder.builder(xContent).startObject().value(e).endObject(); builder = shuffleXContent(builder); - BaseOpenSearchException parsed; + OpenSearchException parsed; try (XContentParser parser = createParser(builder)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = BaseOpenSearchException.fromXContent(parser); + parsed = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -588,14 +588,14 @@ public void testFromXContentWithCause() throws IOException { assertNotNull(parsed); assertEquals(parsed.getMessage(), "OpenSearch exception [type=exception, reason=foo]"); - BaseOpenSearchException cause = (BaseOpenSearchException) parsed.getCause(); + OpenSearchException cause = (OpenSearchException) parsed.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=bar]"); - cause = (BaseOpenSearchException) cause.getCause(); + cause = (OpenSearchException) cause.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=baz]"); - cause = (BaseOpenSearchException) cause.getCause(); + cause = (OpenSearchException) cause.getCause(); assertEquals( cause.getMessage(), "OpenSearch exception [type=routing_missing_exception, reason=routing is required for [_test]/[_id]]" @@ -625,10 +625,10 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { XContentBuilder builder = XContentBuilder.builder(xContent).startObject().value(foo).endObject(); builder = shuffleXContent(builder); - BaseOpenSearchException parsed; + OpenSearchException parsed; try (XContentParser parser = createParser(builder)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsed = BaseOpenSearchException.fromXContent(parser); + parsed = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -640,7 +640,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { assertThat(parsed.getMetadataKeys(), hasSize(1)); assertThat(parsed.getMetadata("opensearch.foo_0"), hasItem("foo0")); - BaseOpenSearchException cause = (BaseOpenSearchException) parsed.getCause(); + OpenSearchException cause = (OpenSearchException) parsed.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=bar]"); assertThat(cause.getHeaderKeys(), hasSize(1)); assertThat(cause.getHeader("bar_1"), hasItem("bar1")); @@ -648,7 +648,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { assertThat(cause.getMetadata("opensearch.bar_0"), hasItem("bar0")); assertThat(cause.getMetadata("opensearch.bar_2"), hasItem("bar2")); - cause = (BaseOpenSearchException) cause.getCause(); + cause = (OpenSearchException) cause.getCause(); assertEquals(cause.getMessage(), "OpenSearch exception [type=exception, reason=baz]"); assertThat(cause.getHeaderKeys(), hasSize(2)); assertThat(cause.getHeader("baz_0"), hasItem("baz0")); @@ -657,7 +657,7 @@ public void testFromXContentWithHeadersAndMetadata() throws IOException { assertThat(cause.getMetadata("opensearch.baz_1"), hasItem("baz1")); assertThat(cause.getMetadata("opensearch.baz_3"), hasItem("baz3")); - cause = (BaseOpenSearchException) cause.getCause(); + cause = (OpenSearchException) cause.getCause(); assertEquals( cause.getMessage(), "OpenSearch exception [type=routing_missing_exception, reason=routing is required for [_test]/[_id]]" @@ -710,10 +710,10 @@ public void testFromXContentWithIgnoredMetadataAndHeaders() throws IOException { } } - BaseOpenSearchException parsedException; + OpenSearchException parsedException; try (XContentParser parser = createParser(xContent, originalBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsedException = BaseOpenSearchException.fromXContent(parser); + parsedException = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -732,7 +732,7 @@ public void testThrowableToAndFromXContent() throws IOException { final Tuple exceptions = randomExceptions(); final Throwable throwable = exceptions.v1(); - final BaseOpenSearchException expected = exceptions.v2(); + final OpenSearchException expected = exceptions.v2(); int suppressedCount = randomBoolean() ? 0 : between(1, 5); for (int i = 0; i < suppressedCount; i++) { final Tuple suppressed = randomExceptions(); @@ -745,10 +745,10 @@ public void testThrowableToAndFromXContent() throws IOException { return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); - BaseOpenSearchException parsedException; + OpenSearchException parsedException; try (XContentParser parser = createParser(xContent, throwableBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsedException = BaseOpenSearchException.fromXContent(parser); + parsedException = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } @@ -773,15 +773,15 @@ public void testUnknownFailureToAndFromXContent() throws IOException { BytesReference failureBytes = toShuffledXContent((builder, params) -> { // Prints a null failure using generateFailureXContent() - BaseOpenSearchException.generateFailureXContent(builder, params, null, randomBoolean()); + OpenSearchException.generateFailureXContent(builder, params, null, randomBoolean()); return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); - BaseOpenSearchException parsedFailure; + OpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - parsedFailure = BaseOpenSearchException.failureFromXContent(parser); + parsedFailure = OpenSearchException.failureFromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } @@ -797,7 +797,7 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException { final Exception failure = (Exception) randomExceptions().v1(); BytesReference failureBytes = toShuffledXContent((builder, params) -> { - BaseOpenSearchException.generateFailureXContent(builder, params, failure, false); + OpenSearchException.generateFailureXContent(builder, params, failure, false); return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); @@ -805,18 +805,18 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException { failureBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } - BaseOpenSearchException parsedFailure; + OpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - parsedFailure = BaseOpenSearchException.failureFromXContent(parser); + parsedFailure = OpenSearchException.failureFromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } assertNotNull(parsedFailure); String reason = BaseExceptionsHelper.summaryMessage(failure); - assertEquals(BaseOpenSearchException.buildMessage("exception", reason, null), parsedFailure.getMessage()); + assertEquals(OpenSearchException.buildMessage("exception", reason, null), parsedFailure.getMessage()); assertEquals(0, parsedFailure.getHeaders().size()); assertEquals(0, parsedFailure.getMetadata().size()); assertNull(parsedFailure.getCause()); @@ -841,7 +841,7 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { case 1: // Simple opensearch exception with headers (other metadata of type number are not parsed) failure = new ParsingException(3, 2, "B", null); - ((BaseOpenSearchException) failure).addHeader("header_name", "0", "1"); + ((OpenSearchException) failure).addHeader("header_name", "0", "1"); expected = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=B]"); expected.addHeader("header_name", "0", "1"); suppressed = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=B]"); @@ -951,7 +951,7 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { Exception finalFailure = failure; BytesReference failureBytes = toShuffledXContent((builder, params) -> { - BaseOpenSearchException.generateFailureXContent(builder, params, finalFailure, true); + OpenSearchException.generateFailureXContent(builder, params, finalFailure, true); return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); @@ -959,11 +959,11 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { failureBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); } - BaseOpenSearchException parsedFailure; + OpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - parsedFailure = BaseOpenSearchException.failureFromXContent(parser); + parsedFailure = OpenSearchException.failureFromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); } @@ -989,7 +989,7 @@ private static void assertExceptionAsJson(Exception e, String expectedJson) thro }, expectedJson); } - public static void assertDeepEquals(BaseOpenSearchException expected, BaseOpenSearchException actual) { + public static void assertDeepEquals(OpenSearchException expected, OpenSearchException actual) { do { if (expected == null) { assertNull(actual); @@ -1012,12 +1012,12 @@ public static void assertDeepEquals(BaseOpenSearchException expected, BaseOpenSe assertNotNull(actualSuppressed); assertEquals(expectedSuppressed.length, actualSuppressed.length); for (int i = 0; i < expectedSuppressed.length; i++) { - assertDeepEquals((BaseOpenSearchException) expectedSuppressed[i], (BaseOpenSearchException) actualSuppressed[i]); + assertDeepEquals((OpenSearchException) expectedSuppressed[i], (OpenSearchException) actualSuppressed[i]); } } - expected = (BaseOpenSearchException) expected.getCause(); - actual = (BaseOpenSearchException) actual.getCause(); + expected = (OpenSearchException) expected.getCause(); + actual = (OpenSearchException) actual.getCause(); if (expected == null) { assertNull(actual); } diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java index b87363525c841..467d825dc0ca5 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java @@ -33,7 +33,6 @@ package org.opensearch.action.bulk; import org.opensearch.BaseExceptionsHelper; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.DocWriteResponse; @@ -148,7 +147,7 @@ public static void assertBulkItemResponse(BulkItemResponse expected, BulkItemRes assertEquals(expectedFailure.getMessage(), actualFailure.getMessage()); assertEquals(expectedFailure.getStatus(), actualFailure.getStatus()); - assertDeepEquals((BaseOpenSearchException) expectedFailure.getCause(), (BaseOpenSearchException) actualFailure.getCause()); + assertDeepEquals((OpenSearchException) expectedFailure.getCause(), (OpenSearchException) actualFailure.getCause()); } else { DocWriteResponse expectedDocResponse = expected.getResponse(); DocWriteResponse actualDocResponse = expected.getResponse(); diff --git a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java index bed8bd34f20f6..169f2d47743d1 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java @@ -32,7 +32,7 @@ package org.opensearch.action.search; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.TimestampParsingException; import org.opensearch.common.ParsingException; @@ -136,10 +136,10 @@ public void testToAndFromXContent() throws IOException { BytesReference exceptionBytes = toShuffledXContent(actual, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); - BaseOpenSearchException parsedException; + OpenSearchException parsedException; try (XContentParser parser = createParser(xContent, exceptionBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - parsedException = BaseOpenSearchException.fromXContent(parser); + parsedException = OpenSearchException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); assertNull(parser.nextToken()); } diff --git a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java index 1b51c00fbc1dd..4aa3542f3ac6b 100644 --- a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java +++ b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java @@ -32,7 +32,6 @@ package org.opensearch.action.support.replication; -import org.opensearch.BaseOpenSearchException; import org.opensearch.OpenSearchException; import org.opensearch.action.support.replication.ReplicationResponse.ShardInfo; import org.opensearch.common.Strings; @@ -154,7 +153,7 @@ public static void assertShardInfo(ShardInfo expected, ShardInfo actual) { assertEquals(expectedFailure.primary(), actualFailure.primary()); OpenSearchException expectedCause = (OpenSearchException) expectedFailure.getCause(); - BaseOpenSearchException actualCause = (BaseOpenSearchException) actualFailure.getCause(); + OpenSearchException actualCause = (OpenSearchException) actualFailure.getCause(); assertDeepEquals(expectedCause, actualCause); } } diff --git a/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java b/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java index 1369e57b71de5..5da0727d23fed 100644 --- a/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java +++ b/server/src/test/java/org/opensearch/tasks/ListTasksResponseTests.java @@ -32,7 +32,7 @@ package org.opensearch.tasks; -import org.opensearch.BaseOpenSearchException; +import org.opensearch.OpenSearchException; import org.opensearch.action.FailedNodeException; import org.opensearch.action.TaskOperationFailure; import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse; @@ -158,15 +158,15 @@ protected void assertEqualInstances(ListTasksResponse expectedInstance, ListTask assertOnTaskFailures(newInstance.getTaskFailures(), expectedInstance.getTaskFailures()); } - protected static void assertOnNodeFailures(List nodeFailures, List expectedFailures) { + protected static void assertOnNodeFailures(List nodeFailures, List expectedFailures) { assertThat(nodeFailures.size(), equalTo(expectedFailures.size())); for (int i = 0; i < nodeFailures.size(); i++) { - BaseOpenSearchException newException = nodeFailures.get(i); - BaseOpenSearchException expectedException = expectedFailures.get(i); + OpenSearchException newException = nodeFailures.get(i); + OpenSearchException expectedException = expectedFailures.get(i); assertThat(newException.getMetadata("opensearch.node_id").get(0), equalTo(((FailedNodeException) expectedException).nodeId())); assertThat(newException.getMessage(), equalTo("OpenSearch exception [type=failed_node_exception, reason=error message]")); - assertThat(newException.getCause(), instanceOf(BaseOpenSearchException.class)); - BaseOpenSearchException cause = (BaseOpenSearchException) newException.getCause(); + assertThat(newException.getCause(), instanceOf(OpenSearchException.class)); + OpenSearchException cause = (OpenSearchException) newException.getCause(); assertThat(cause.getMessage(), equalTo("OpenSearch exception [type=connect_exception, reason=null]")); } } @@ -179,8 +179,8 @@ protected static void assertOnTaskFailures(List taskFailur assertThat(newFailure.getNodeId(), equalTo(expectedFailure.getNodeId())); assertThat(newFailure.getTaskId(), equalTo(expectedFailure.getTaskId())); assertThat(newFailure.getStatus(), equalTo(expectedFailure.getStatus())); - assertThat(newFailure.getCause(), instanceOf(BaseOpenSearchException.class)); - BaseOpenSearchException cause = (BaseOpenSearchException) newFailure.getCause(); + assertThat(newFailure.getCause(), instanceOf(OpenSearchException.class)); + OpenSearchException cause = (OpenSearchException) newFailure.getCause(); assertThat(cause.getMessage(), equalTo("OpenSearch exception [type=illegal_state_exception, reason=null]")); } } From 38faa2f5a20712ecb486a811ccf55fb5909bd823 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 14 Jun 2023 11:06:01 -0500 Subject: [PATCH 4/8] move BytesReferenceUtil.bytes back to BytesReference Signed-off-by: Nicholas Walter Knize --- .../opensearch/client/RequestConverters.java | 5 +- .../client/core/TermVectorsRequest.java | 3 +- .../client/indices/CreateIndexRequest.java | 11 ++- .../indices/GetFieldMappingsResponse.java | 3 +- .../indices/PutIndexTemplateRequest.java | 11 ++- .../client/indices/PutMappingRequest.java | 3 +- .../java/org/opensearch/client/CrudIT.java | 3 +- .../org/opensearch/client/IngestClientIT.java | 14 ++-- ...OpenSearchRestHighLevelClientTestCase.java | 8 +- .../client/RequestConvertersTests.java | 5 +- .../client/RestHighLevelClientTests.java | 4 +- .../java/org/opensearch/client/SearchIT.java | 3 +- .../client/SearchPipelineClientIT.java | 8 +- .../core/tasks/GetTaskResponseTests.java | 4 +- .../StoredScriptsDocumentationIT.java | 6 +- .../GetIndexTemplatesResponseTests.java | 5 +- .../common/bytes/BytesReference.java | 17 ++++ .../common/io/stream/BytesStream.java | 0 .../xcontent/MapXContentParserTests.java | 6 +- .../common/xcontent/XContentParserTests.java | 8 +- .../ingest/common/ScriptProcessor.java | 4 +- .../common/GrokProcessorGetActionTests.java | 5 +- .../ingest/common/JsonProcessorTests.java | 4 +- .../geoip/GeoIpProcessorNonIngestNodeIT.java | 3 +- .../mustache/MultiSearchTemplateRequest.java | 6 +- .../mustache/SearchTemplateResponse.java | 9 +-- .../script/mustache/MustacheTests.java | 6 +- .../SearchTemplateRequestXContentTests.java | 6 +- .../mustache/SearchTemplateResponseTests.java | 9 +-- .../action/PainlessExecuteAction.java | 3 +- .../action/PainlessExecuteRequestTests.java | 5 +- .../RankFeatureMetaFieldMapperTests.java | 3 +- .../mapper/ScaledFloatFieldMapperTests.java | 20 ++--- .../mapper/ParentJoinFieldMapperTests.java | 38 ++++----- .../percolator/PercolatorQuerySearchIT.java | 81 +++++++++---------- .../percolator/PercolateQueryBuilder.java | 3 +- .../PercolateQueryBuilderTests.java | 3 +- .../PercolatorFieldMapperTests.java | 36 ++++----- .../PercolatorQuerySearchTests.java | 15 ++-- .../index/rankeval/RankEvalResponseTests.java | 3 +- .../index/rankeval/RankEvalSpecTests.java | 3 +- .../AbstractBulkByQueryRestHandler.java | 4 +- .../opensearch/index/reindex/Reindexer.java | 4 +- .../reindex/remote/RemoteResponseParsers.java | 4 +- .../index/reindex/RestReindexActionTests.java | 4 +- .../common/FilterQueryRequestProcessor.java | 4 +- .../common/RenameFieldResponseProcessor.java | 3 +- .../common/ScriptRequestProcessor.java | 4 +- .../index/mapper/size/SizeMappingTests.java | 7 +- .../gcs/GoogleCloudStorageServiceTests.java | 3 +- .../action/bulk/BulkIntegrationIT.java | 4 +- .../java/org/opensearch/get/GetActionIT.java | 3 +- .../org/opensearch/ingest/IngestClientIT.java | 27 +++---- ...gestProcessorNotInstalledOnAllNodesIT.java | 3 +- .../org/opensearch/mget/SimpleMgetIT.java | 3 +- .../aggregations/FiltersAggsRewriteIT.java | 3 +- .../search/fields/SearchFieldsIT.java | 3 +- .../opensearch/search/geo/GeoFilterIT.java | 9 +-- .../search/scroll/SearchScrollIT.java | 4 +- .../SnapshotCustomPluginStateIT.java | 3 +- .../org/opensearch/update/UpdateNoopIT.java | 4 +- .../ClusterDeleteWeightedRoutingRequest.java | 3 +- .../put/ClusterPutWeightedRoutingRequest.java | 3 +- .../create/CreateSnapshotRequest.java | 4 +- .../indices/create/CreateIndexRequest.java | 9 +-- .../mapping/get/GetFieldMappingsResponse.java | 3 +- .../mapping/put/PutMappingRequest.java | 5 +- .../template/put/PutIndexTemplateRequest.java | 9 +-- .../opensearch/action/index/IndexRequest.java | 3 +- .../action/ingest/GetPipelineResponse.java | 4 +- .../search/GetSearchPipelineResponse.java | 4 +- .../action/search/MultiSearchRequest.java | 5 +- .../termvectors/TermVectorsRequest.java | 3 +- .../action/update/UpdateHelper.java | 3 +- .../cluster/metadata/AliasMetadata.java | 4 +- .../cluster/metadata/MappingMetadata.java | 4 +- .../MetadataIndexTemplateService.java | 4 +- .../java/org/opensearch/common/Strings.java | 3 +- .../common/util/BytesReferenceUtil.java | 38 --------- .../xcontent/JsonToStringXContentParser.java | 4 +- .../common/xcontent/ObjectParserHelper.java | 3 +- .../common/xcontent/XContentHelper.java | 7 +- .../org/opensearch/index/get/GetResult.java | 3 +- .../opensearch/index/get/ShardGetService.java | 5 +- .../index/query/MoreLikeThisQueryBuilder.java | 5 +- .../functionscore/DecayFunctionBuilder.java | 3 +- .../functionscore/DecayFunctionParser.java | 3 +- .../index/reindex/ReindexRequest.java | 4 +- .../opensearch/index/reindex/RemoteInfo.java | 5 +- .../opensearch/ingest/ConfigurationUtils.java | 4 +- .../ingest/PipelineConfiguration.java | 3 +- .../blobstore/BlobStoreRepository.java | 5 +- .../opensearch/rest/BytesRestResponse.java | 5 +- .../opensearch/rest/RestRequestFilter.java | 3 +- .../java/org/opensearch/script/Script.java | 4 +- .../java/org/opensearch/search/SearchHit.java | 3 +- .../fetch/subphase/FetchSourcePhase.java | 4 +- .../pipeline/PipelineConfiguration.java | 3 +- .../CompletionSuggestionBuilder.java | 5 +- .../java/org/opensearch/tasks/TaskResult.java | 3 +- .../opensearch/OpenSearchExceptionTests.java | 11 ++- .../action/DocWriteResponseTests.java | 6 +- .../node/tasks/TransportTasksActionTests.java | 4 +- .../RestoreRemoteStoreRequestTests.java | 4 +- .../stats/RemoteStoreStatsResponseTests.java | 9 +-- .../stats/RemoteStoreStatsTests.java | 4 +- .../put/PutRepositoryRequestTests.java | 4 +- .../reroute/ClusterRerouteRequestTests.java | 4 +- .../ClusterUpdateSettingsRequestTests.java | 3 +- .../create/CreateSnapshotRequestTests.java | 4 +- .../restore/RestoreSnapshotRequestTests.java | 4 +- .../PutStoredScriptRequestTests.java | 5 +- .../indices/analyze/AnalyzeResponseTests.java | 5 +- .../rollover/RolloverRequestTests.java | 3 +- .../IndicesShardStoreResponseTests.java | 3 +- .../action/bulk/BulkItemResponseTests.java | 3 +- .../action/explain/ExplainResponseTests.java | 4 +- .../MergedFieldCapabilitiesResponseTests.java | 4 +- .../get/TransportMultiGetActionTests.java | 6 +- .../ingest/GetPipelineResponseTests.java | 6 +- .../ingest/PutPipelineRequestTests.java | 7 +- .../ingest/WriteableIngestDocumentTests.java | 4 +- .../search/MultiSearchRequestTests.java | 4 +- ...ultShardOperationFailedExceptionTests.java | 4 +- .../action/support/IndicesOptionsTests.java | 7 +- .../replication/ReplicationResponseTests.java | 3 +- .../TransportMultiTermVectorsActionTests.java | 6 +- .../action/update/UpdateRequestTests.java | 3 +- .../CoordinationMetadataTests.java | 6 +- .../OpenSearchNodeCommandTests.java | 4 +- .../cluster/metadata/IndexGraveyardTests.java | 4 +- .../cluster/metadata/IndexMetadataTests.java | 4 +- .../metadata/IndexTemplateMetadataTests.java | 3 +- .../cluster/metadata/ManifestTests.java | 3 +- .../cluster/metadata/MetadataTests.java | 11 ++- .../cluster/routing/AllocationIdTests.java | 3 +- .../common/geo/GeoJsonSerializationTests.java | 4 +- .../opensearch/common/geo/GeoUtilTests.java | 4 +- .../common/xcontent/BaseXContentTestCase.java | 35 ++++---- .../common/xcontent/XContentFactoryTests.java | 3 +- .../builder/XContentBuilderTests.java | 8 +- .../cbor/CborXContentParserTests.java | 3 +- .../support/AbstractFilteringTestCase.java | 5 +- .../xcontent/support/XContentHelperTests.java | 5 +- .../support/XContentMapValuesTests.java | 32 ++------ .../AbstractXContentFilteringTestCase.java | 6 +- .../java/org/opensearch/index/IndexTests.java | 4 +- .../index/IndexingSlowLogTests.java | 5 +- .../fielddata/BinaryDVFieldDataTests.java | 10 +-- .../mapper/CompletionFieldMapperTests.java | 4 +- .../index/mapper/CopyToMapperTests.java | 4 +- .../mapper/DataStreamFieldMapperTests.java | 12 +-- .../index/mapper/DynamicMappingTests.java | 3 +- .../mapper/FieldNamesFieldMapperTests.java | 8 +- .../mapper/FlatObjectFieldDataTests.java | 4 +- .../index/mapper/IdFieldMapperTests.java | 4 +- .../index/mapper/IndexFieldMapperTests.java | 4 +- .../index/mapper/IpRangeFieldMapperTests.java | 4 +- .../mapper/JavaMultiFieldMergeTests.java | 5 +- .../index/mapper/MapperServiceTests.java | 24 +++--- .../index/mapper/NestedObjectMapperTests.java | 38 +++++---- .../mapper/NullValueObjectMappingTests.java | 10 +-- .../index/mapper/RoutingFieldMapperTests.java | 6 +- .../index/mapper/SourceFieldMapperTests.java | 10 +-- .../mapper/StoredNumericValuesTests.java | 4 +- .../index/mapper/TypeParsersTests.java | 4 +- .../index/mapper/UpdateMappingTests.java | 4 +- .../index/reindex/ReindexRequestTests.java | 7 +- .../search/geo/GeoPointParsingTests.java | 28 +++---- .../snapshots/blobstore/FileInfoTests.java | 5 +- ...oteStoreShardShallowCopySnapshotTests.java | 3 +- .../ingest/PipelineConfigurationTests.java | 3 +- .../opensearch/repositories/IndexIdTests.java | 4 +- .../repositories/RepositoryDataTests.java | 4 +- .../rest/BytesRestResponseTests.java | 4 +- .../opensearch/rest/RestControllerTests.java | 3 +- .../rest/action/RestMainActionTests.java | 3 +- .../indices/RestCreateIndexActionTests.java | 8 +- .../script/ScriptMetadataTests.java | 26 +++--- .../opensearch/script/ScriptServiceTests.java | 3 +- .../script/StoredScriptSourceTests.java | 4 +- .../opensearch/script/StoredScriptTests.java | 26 +++--- .../aggregations/AggregationsTests.java | 3 +- .../AggregatorFactoriesTests.java | 3 +- .../bucket/histogram/DoubleBoundsTests.java | 5 +- .../bucket/histogram/LongBoundsTests.java | 5 +- .../metrics/InternalTopHitsTests.java | 6 +- .../builder/SearchSourceBuilderTests.java | 7 +- .../fetch/subphase/FetchSourcePhaseTests.java | 4 +- .../fetch/subphase/FieldFetcherTests.java | 4 +- .../searchafter/SearchAfterBuilderTests.java | 4 +- .../search/suggest/SuggestTests.java | 3 +- .../CategoryContextMappingTests.java | 52 ++++++------ .../completion/GeoContextMappingTests.java | 20 ++--- .../completion/GeoQueryContextTests.java | 6 +- .../snapshots/SnapshotRequestsTests.java | 5 +- .../org/opensearch/tasks/TaskInfoTests.java | 4 +- .../ThreadPoolSerializationTests.java | 6 +- .../index/engine/EngineTestCase.java | 3 +- .../index/mapper/MapperServiceTestCase.java | 6 +- .../index/mapper/MapperTestCase.java | 8 +- .../search/RandomSearchRequestGenerator.java | 4 +- .../AbstractSnapshotIntegTestCase.java | 5 +- .../test/AbstractXContentTestCase.java | 5 +- .../test/OpenSearchIntegTestCase.java | 13 ++- .../opensearch/test/OpenSearchTestCase.java | 7 +- .../org/opensearch/test/RandomObjects.java | 3 +- .../opensearch/test/XContentTestUtils.java | 7 +- .../yaml/ClientYamlTestExecutionContext.java | 4 +- .../test/AbstractXContentTestCaseTests.java | 3 +- .../test/XContentTestUtilsTests.java | 20 ++--- .../hamcrest/OpenSearchAssertionsTests.java | 34 ++------ .../test/rest/yaml/ObjectPathTests.java | 22 ++--- .../test/test/OpenSearchTestCaseTests.java | 3 +- 214 files changed, 677 insertions(+), 876 deletions(-) rename {server => libs/core}/src/main/java/org/opensearch/common/io/stream/BytesStream.java (100%) delete mode 100644 server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java index ffdf3c3e290c7..007761d9ab473 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java @@ -76,7 +76,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -237,7 +236,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException { } metadata.endObject(); - BytesRef metadataSource = BytesReferenceUtil.bytes(metadata).toBytesRef(); + BytesRef metadataSource = BytesReference.bytes(metadata).toBytesRef(); content.write(metadataSource.bytes, metadataSource.offset, metadataSource.length); content.write(separator); } @@ -263,7 +262,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException { ) { try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) { builder.copyCurrentStructure(parser); - source = BytesReferenceUtil.bytes(builder).toBytesRef(); + source = BytesReference.bytes(builder).toBytesRef(); } } } else if (opType == DocWriteRequest.OpType.UPDATE) { diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java index bf0456a6c9221..2384cef68ade0 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/core/TermVectorsRequest.java @@ -35,7 +35,6 @@ import org.opensearch.client.Validatable; import org.opensearch.common.Nullable; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; @@ -281,7 +280,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (perFieldAnalyzer != null) builder.field("per_field_analyzer", perFieldAnalyzer); if (docBuilder != null) { - BytesReference doc = BytesReferenceUtil.bytes(docBuilder); + BytesReference doc = BytesReference.bytes(docBuilder); try (InputStream stream = doc.streamInput()) { builder.rawField("doc", stream, docBuilder.contentType()); } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java index 0a5f1070722a4..2206e732aa00e 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java @@ -42,7 +42,6 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -202,7 +201,7 @@ public CreateIndexRequest mapping(String source, MediaType mediaType) { * @param source The mapping source */ public CreateIndexRequest mapping(XContentBuilder source) { - return mapping(BytesReferenceUtil.bytes(source), source.contentType()); + return mapping(BytesReference.bytes(source), source.contentType()); } /** @@ -216,7 +215,7 @@ public CreateIndexRequest mapping(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); - return mapping(BytesReferenceUtil.bytes(builder), builder.contentType()); + return mapping(BytesReference.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -266,7 +265,7 @@ public CreateIndexRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReferenceUtil.bytes(builder), builder.contentType()); + return aliases(BytesReference.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -276,7 +275,7 @@ public CreateIndexRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public CreateIndexRequest aliases(XContentBuilder source) { - return aliases(BytesReferenceUtil.bytes(source), source.contentType()); + return aliases(BytesReference.bytes(source), source.contentType()); } /** @@ -373,7 +372,7 @@ public CreateIndexRequest source(String source, MediaType mediaType) { * Note that the mapping definition should *not* be nested under a type name. */ public CreateIndexRequest source(XContentBuilder source) { - return source(BytesReferenceUtil.bytes(source), source.contentType()); + return source(BytesReference.bytes(source), source.contentType()); } /** diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java index f480bfded7daa..091c7f39e41da 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/GetFieldMappingsResponse.java @@ -32,7 +32,6 @@ package org.opensearch.client.indices; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ConstructingObjectParser; @@ -130,7 +129,7 @@ public static class FieldMappingMetadata { PARSER.declareField(optionalConstructorArg(), (p, c) -> p.text(), FULL_NAME, ObjectParser.ValueType.STRING); PARSER.declareField(optionalConstructorArg(), (p, c) -> { final XContentBuilder jsonBuilder = jsonBuilder().copyCurrentStructure(p); - final BytesReference bytes = BytesReferenceUtil.bytes(jsonBuilder); + final BytesReference bytes = BytesReference.bytes(jsonBuilder); return bytes; }, MAPPING, ObjectParser.ValueType.OBJECT); } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java index 468b308e63608..c6d6a29a02af1 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java @@ -42,7 +42,6 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -242,7 +241,7 @@ public String cause() { * @param source The mapping source */ public PutIndexTemplateRequest mapping(XContentBuilder source) { - internalMapping(XContentHelper.convertToMap(BytesReferenceUtil.bytes(source), true, source.contentType()).v2()); + internalMapping(XContentHelper.convertToMap(BytesReference.bytes(source), true, source.contentType()).v2()); return this; } @@ -273,7 +272,7 @@ private PutIndexTemplateRequest internalMapping(Map source) { MediaType mediaType = builder.contentType(); Objects.requireNonNull(mediaType); try { - mappings = new BytesArray(XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder), false, false, mediaType)); + mappings = new BytesArray(XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, mediaType)); return this; } catch (IOException e) { throw new UncheckedIOException("failed to convert source to json", e); @@ -292,7 +291,7 @@ public BytesReference mappings() { */ public PutIndexTemplateRequest source(XContentBuilder templateBuilder) { try { - return source(BytesReferenceUtil.bytes(templateBuilder), templateBuilder.contentType()); + return source(BytesReference.bytes(templateBuilder), templateBuilder.contentType()); } catch (Exception e) { throw new IllegalArgumentException("Failed to build json for template request", e); } @@ -422,7 +421,7 @@ public PutIndexTemplateRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReferenceUtil.bytes(builder)); + return aliases(BytesReference.bytes(builder)); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -432,7 +431,7 @@ public PutIndexTemplateRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public PutIndexTemplateRequest aliases(XContentBuilder source) { - return aliases(BytesReferenceUtil.bytes(source)); + return aliases(BytesReference.bytes(source)); } /** diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java index fbd32ddae2e26..3d05c12b7ba1f 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java @@ -38,7 +38,6 @@ import org.opensearch.client.TimedRequest; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.MediaType; @@ -161,7 +160,7 @@ public PutMappingRequest source(String mappingSource, MediaType mediaType) { * Note that the definition should *not* be nested under a type name. */ public PutMappingRequest source(XContentBuilder builder) { - this.source = BytesReferenceUtil.bytes(builder); + this.source = BytesReference.bytes(builder); this.mediaType = builder.contentType(); return this; } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java index ea3ef8e152861..06a6fb6802e3c 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java @@ -62,7 +62,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -863,7 +862,7 @@ public void testBulk() throws IOException { bulkRequest.add(deleteRequest); } else { - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( XContentBuilder.builder(xContentType.xContent()).startObject().field("id", i).endObject() ); if (opType == DocWriteRequest.OpType.INDEX) { diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java index d6b13421bf4e2..4e67198422b23 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/IngestClientIT.java @@ -42,7 +42,7 @@ import org.opensearch.action.ingest.SimulatePipelineRequest; import org.opensearch.action.ingest.SimulatePipelineResponse; import org.opensearch.action.support.master.AcknowledgedResponse; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.PipelineConfiguration; @@ -58,7 +58,7 @@ public class IngestClientIT extends OpenSearchRestHighLevelClientTestCase { public void testPutPipeline() throws IOException { String id = "some_pipeline_id"; XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); - PutPipelineRequest request = new PutPipelineRequest(id, BytesReferenceUtil.bytes(pipelineBuilder), pipelineBuilder.contentType()); + PutPipelineRequest request = new PutPipelineRequest(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType()); AcknowledgedResponse putPipelineResponse = execute( request, @@ -72,11 +72,7 @@ public void testGetPipeline() throws IOException { String id = "some_pipeline_id"; XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); { - PutPipelineRequest request = new PutPipelineRequest( - id, - BytesReferenceUtil.bytes(pipelineBuilder), - pipelineBuilder.contentType() - ); + PutPipelineRequest request = new PutPipelineRequest(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType()); createPipeline(request); } @@ -91,7 +87,7 @@ public void testGetPipeline() throws IOException { assertEquals(response.pipelines().get(0).getId(), id); PipelineConfiguration expectedConfig = new PipelineConfiguration( id, - BytesReferenceUtil.bytes(pipelineBuilder), + BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType() ); assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap()); @@ -166,7 +162,7 @@ private void testSimulatePipeline(boolean isVerbose, boolean isFailure) throws I builder.endObject(); SimulatePipelineRequest request = new SimulatePipelineRequest( - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), XContentType.fromMediaType(builder.contentType()) ); request.setVerbose(isVerbose); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java index 07e0cb0fd88cd..c1e2420d86d20 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/OpenSearchRestHighLevelClientTestCase.java @@ -48,8 +48,8 @@ import org.opensearch.client.indices.CreateIndexRequest; import org.opensearch.common.Booleans; import org.opensearch.common.CheckedRunnable; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -223,12 +223,12 @@ protected static void createFieldAddingPipleine(String id, String fieldName, Str .endArray() .endObject(); - createPipeline(new PutPipelineRequest(id, BytesReferenceUtil.bytes(pipeline), XContentType.JSON)); + createPipeline(new PutPipelineRequest(id, BytesReference.bytes(pipeline), XContentType.JSON)); } protected static void createPipeline(String pipelineId) throws IOException { XContentBuilder builder = buildRandomXContentPipeline(); - createPipeline(new PutPipelineRequest(pipelineId, BytesReferenceUtil.bytes(builder), builder.contentType())); + createPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(builder), builder.contentType())); } protected static void createPipeline(PutPipelineRequest putPipelineRequest) throws IOException { @@ -266,7 +266,7 @@ protected void putConflictPipeline() throws IOException { .endObject(); final PutPipelineRequest putPipelineRequest = new PutPipelineRequest( CONFLICT_PIPELINE_ID, - BytesReferenceUtil.bytes(pipelineBuilder), + BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType() ); assertTrue(highLevelClient().ingest().putPipeline(putPipelineRequest, RequestOptions.DEFAULT).isAcknowledged()); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java index 3e0db1179879d..ca880d2f3d022 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java @@ -72,7 +72,6 @@ import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -425,7 +424,7 @@ public void testReindex() throws IOException { "remote-host", 9200, null, - BytesReferenceUtil.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)), + BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)), "user", "pass", emptyMap(), @@ -1704,7 +1703,7 @@ public void testPutScript() throws Exception { builder.startObject("script").field("lang", "painless").field("source", "Math.log(_score * 2) + params.multiplier").endObject(); builder.endObject(); - putStoredScriptRequest.content(BytesReferenceUtil.bytes(builder), xContentType); + putStoredScriptRequest.content(BytesReference.bytes(builder), xContentType); } Map expectedParams = new HashMap<>(); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java index 09f055730f72a..85f329eb6e895 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java @@ -46,8 +46,8 @@ import org.opensearch.client.core.MainRequest; import org.opensearch.client.core.MainResponse; import org.opensearch.common.CheckedFunction; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -340,7 +340,7 @@ private static HttpEntity createBinaryEntity(XContentBuilder xContentBuilder, Co builder.startObject(); builder.field("field", "value"); builder.endObject(); - return new ByteArrayEntity(BytesReferenceUtil.bytes(builder).toBytesRef().bytes, contentType); + return new ByteArrayEntity(BytesReference.bytes(builder).toBytesRef().bytes, contentType); } } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java index 50c6564ec0fd7..41d8ce2a2fed9 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java @@ -55,7 +55,6 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -1188,7 +1187,7 @@ public void testRenderSearchTemplate() throws IOException { ); assertNull(searchTemplateResponse.getResponse()); - BytesReference expectedSource = BytesReferenceUtil.bytes( + BytesReference expectedSource = BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("query") diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java index d13025e69da8e..ea27d8e9605d9 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/SearchPipelineClientIT.java @@ -13,7 +13,7 @@ import org.opensearch.action.search.GetSearchPipelineResponse; import org.opensearch.action.search.PutSearchPipelineRequest; import org.opensearch.action.support.master.AcknowledgedResponse; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -26,7 +26,7 @@ public void testPutPipeline() throws IOException { XContentBuilder pipelineBuilder = buildSearchPipeline(); PutSearchPipelineRequest request = new PutSearchPipelineRequest( id, - BytesReferenceUtil.bytes(pipelineBuilder), + BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType() ); createPipeline(request); @@ -46,7 +46,7 @@ public void testGetPipeline() throws IOException { XContentBuilder pipelineBuilder = buildSearchPipeline(); PutSearchPipelineRequest request = new PutSearchPipelineRequest( id, - BytesReferenceUtil.bytes(pipelineBuilder), + BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType() ); createPipeline(request); @@ -67,7 +67,7 @@ public void testDeletePipeline() throws IOException { XContentBuilder pipelineBuilder = buildSearchPipeline(); PutSearchPipelineRequest request = new PutSearchPipelineRequest( id, - BytesReferenceUtil.bytes(pipelineBuilder), + BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType() ); createPipeline(request); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java index 2af978ac09c7e..01b980a95f1b1 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/core/tasks/GetTaskResponseTests.java @@ -34,7 +34,7 @@ import org.opensearch.client.Requests; import org.opensearch.client.tasks.GetTaskResponse; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.tasks.RawTaskStatus; @@ -132,7 +132,7 @@ private static RawTaskStatus randomRawTaskStatus() { builder.field(randomAlphaOfLength(5), randomAlphaOfLength(5)); } builder.endObject(); - return new RawTaskStatus(BytesReferenceUtil.bytes(builder)); + return new RawTaskStatus(BytesReference.bytes(builder)); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java index 91921d1d64821..bd9cbbdc2f450 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/documentation/StoredScriptsDocumentationIT.java @@ -43,8 +43,8 @@ import org.opensearch.client.RequestOptions; import org.opensearch.client.RestHighLevelClient; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -255,7 +255,7 @@ public void testPutScript() throws Exception { builder.endObject(); } builder.endObject(); - request.content(BytesReferenceUtil.bytes(builder), XContentType.JSON); // <1> + request.content(BytesReference.bytes(builder), XContentType.JSON); // <1> // end::put-stored-script-content-painless // tag::put-stored-script-execute @@ -310,7 +310,7 @@ public void onFailure(Exception e) { builder.endObject(); } builder.endObject(); - request.content(BytesReferenceUtil.bytes(builder), XContentType.JSON); // <1> + request.content(BytesReference.bytes(builder), XContentType.JSON); // <1> // end::put-stored-script-content-mustache client.putScript(request, RequestOptions.DEFAULT); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java index 89e024df4db73..79d4683ae09ae 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexTemplatesResponseTests.java @@ -38,7 +38,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -98,7 +97,7 @@ public void testParsingFromOpenSearchResponse() throws IOException { ); esIMD.patterns(Arrays.asList(generateRandomStringArray(32, 4, false, false))); esIMD.settings(randomIndexSettings()); - esIMD.putMapping("_doc", new CompressedXContent(BytesReferenceUtil.bytes(randomMapping("_doc", xContentType)))); + esIMD.putMapping("_doc", new CompressedXContent(BytesReference.bytes(randomMapping("_doc", xContentType)))); int numAliases = randomIntBetween(0, 8); for (int j = 0; j < numAliases; j++) { esIMD.putAlias(randomAliasMetadata(String.format(Locale.ROOT, "%02d ", j) + randomAlphaOfLength(4))); @@ -115,7 +114,7 @@ public void testParsingFromOpenSearchResponse() throws IOException { XContentParser parser = XContentHelper.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(xContentBuilder), + BytesReference.bytes(xContentBuilder), xContentType ) ) { diff --git a/libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java b/libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java index 41e6044a67eea..5bafd24e1e928 100644 --- a/libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java +++ b/libs/core/src/main/java/org/opensearch/common/bytes/BytesReference.java @@ -35,10 +35,13 @@ import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefIterator; +import org.opensearch.common.io.stream.BytesStream; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.util.ByteArray; import org.opensearch.core.xcontent.ToXContentFragment; +import org.opensearch.core.xcontent.XContentBuilder; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; @@ -51,6 +54,20 @@ */ public interface BytesReference extends Comparable, ToXContentFragment { + /** + * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder, + * so no further fields may be added. + */ + static BytesReference bytes(XContentBuilder xContentBuilder) { + xContentBuilder.close(); + OutputStream stream = xContentBuilder.getOutputStream(); + if (stream instanceof ByteArrayOutputStream) { + return new BytesArray(((ByteArrayOutputStream) stream).toByteArray()); + } else { + return ((BytesStream) stream).bytes(); + } + } + /** * Returns a compact array from the given BytesReference. The returned array won't be copied unless necessary. If you need * to modify the returned array use {@code BytesRef.deepCopyOf(reference.toBytesRef()} instead diff --git a/server/src/main/java/org/opensearch/common/io/stream/BytesStream.java b/libs/core/src/main/java/org/opensearch/common/io/stream/BytesStream.java similarity index 100% rename from server/src/main/java/org/opensearch/common/io/stream/BytesStream.java rename to libs/core/src/main/java/org/opensearch/common/io/stream/BytesStream.java diff --git a/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java b/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java index ecccfa936a6ac..f15823481180b 100644 --- a/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java +++ b/libs/x-content/src/test/java/org/opensearch/common/xcontent/MapXContentParserTests.java @@ -33,7 +33,7 @@ package org.opensearch.common.xcontent; import org.opensearch.common.CheckedConsumer; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.MapXContentParser; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -98,11 +98,11 @@ public void compareTokens(CheckedConsumer consumer try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { consumer.accept(builder); final Map map; - try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { map = parser.mapOrdered(); } - try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { try ( XContentParser mapParser = new MapXContentParser( xContentRegistry(), diff --git a/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java b/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java index 35186794f083d..2920a1ae6cf04 100644 --- a/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java +++ b/libs/x-content/src/test/java/org/opensearch/common/xcontent/XContentParserTests.java @@ -38,7 +38,7 @@ import org.opensearch.common.CheckedSupplier; import org.opensearch.common.Strings; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.cbor.CborXContent; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.common.xcontent.smile.SmileXContent; @@ -110,7 +110,7 @@ public void testStringOffLimit() throws IOException { } builder.endObject(); - try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(field, parser.currentName()); @@ -140,7 +140,7 @@ public void testString() throws IOException { builder.endObject(); final String text; - try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(field, parser.currentName()); @@ -172,7 +172,7 @@ public void testFloat() throws IOException { builder.endObject(); final Number number; - try (XContentParser parser = createParser(xContentType.xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xContentType.xContent(), BytesReference.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(field, parser.currentName()); diff --git a/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java index bd0f923e37484..a7825edcf6b3a 100644 --- a/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/opensearch/ingest/common/ScriptProcessor.java @@ -33,7 +33,7 @@ package org.opensearch.ingest.common; import org.opensearch.common.Nullable; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -136,7 +136,7 @@ public ScriptProcessor create( ) throws Exception { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); + InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java index 1ef3a38d519a9..db8c04cca7c80 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/GrokProcessorGetActionTests.java @@ -34,9 +34,9 @@ import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -123,8 +123,7 @@ public void testResponseToXContent() throws Exception { GrokProcessorGetAction.Response response = new GrokProcessorGetAction.Response(TEST_PATTERNS); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - Map converted = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()) - .v2(); + Map converted = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); Map patterns = (Map) converted.get("patterns"); assertThat(patterns.size(), equalTo(2)); assertThat(patterns.get("PATTERN1"), equalTo("foo1")); diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java index 6c9796b981e9b..f2cc33e10abfe 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/JsonProcessorTests.java @@ -32,7 +32,7 @@ package org.opensearch.ingest.common; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -61,7 +61,7 @@ public void testExecute() throws Exception { Map randomJsonMap = RandomDocumentPicks.randomSource(random()); XContentBuilder builder = JsonXContent.contentBuilder().map(randomJsonMap); - String randomJson = XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder), false, XContentType.JSON); + String randomJson = XContentHelper.convertToJson(BytesReference.bytes(builder), false, XContentType.JSON); document.put(randomField, randomJson); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); diff --git a/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java b/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java index 47b02223fd911..6ec147c7390a9 100644 --- a/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java +++ b/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java @@ -39,7 +39,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -157,7 +156,7 @@ public void testLazyLoading() throws IOException { builder.endArray(); } builder.endObject(); - bytes = BytesReferenceUtil.bytes(builder); + bytes = BytesReference.bytes(builder); } assertAcked(client().admin().cluster().putPipeline(new PutPipelineRequest("geoip", bytes, XContentType.JSON)).actionGet()); // the geo-IP databases should not be loaded on any nodes as they are all non-ingest nodes diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java index 34ac30bb439d3..35363275da304 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateRequest.java @@ -38,9 +38,9 @@ import org.opensearch.action.search.MultiSearchRequest; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.support.IndicesOptions; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -164,12 +164,12 @@ public static byte[] writeMultiLineFormat(MultiSearchTemplateRequest multiSearch final SearchRequest searchRequest = templateRequest.getRequest(); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { MultiSearchRequest.writeSearchRequestParams(searchRequest, xContentBuilder); - BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); + BytesReference.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { templateRequest.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); - BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); + BytesReference.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); } diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java index 88ba637c43ebf..87f3b9f902b8f 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/SearchTemplateResponse.java @@ -34,7 +34,6 @@ import org.opensearch.action.ActionResponse; import org.opensearch.action.search.SearchResponse; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -106,16 +105,12 @@ public static SearchTemplateResponse fromXContent(XContentParser parser) throws if (contentAsMap.containsKey(TEMPLATE_OUTPUT_FIELD.getPreferredName())) { Object source = contentAsMap.get(TEMPLATE_OUTPUT_FIELD.getPreferredName()); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).value(source); - searchTemplateResponse.setSource(BytesReferenceUtil.bytes(builder)); + searchTemplateResponse.setSource(BytesReference.bytes(builder)); } else { MediaType contentType = parser.contentType(); XContentBuilder builder = XContentFactory.contentBuilder(contentType).map(contentAsMap); XContentParser searchResponseParser = contentType.xContent() - .createParser( - parser.getXContentRegistry(), - parser.getDeprecationHandler(), - BytesReferenceUtil.bytes(builder).streamInput() - ); + .createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), BytesReference.bytes(builder).streamInput()); SearchResponse searchResponse = SearchResponse.fromXContent(searchResponseParser); searchTemplateResponse.setResponse(searchResponse); diff --git a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java index 30168b42b82df..bc44821416fbe 100644 --- a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java +++ b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/MustacheTests.java @@ -31,7 +31,7 @@ package org.opensearch.script.mustache; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.script.ScriptEngine; @@ -276,7 +276,7 @@ public void testEmbeddedToJSON() throws Exception { Map ctx = singletonMap( "ctx", - XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2() + XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2() ); assertScript( @@ -322,7 +322,7 @@ public void testEmbeddedArrayJoin() throws Exception { Map ctx = singletonMap( "ctx", - XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2() + XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2() ); assertScript("{{#join}}ctx.people.0.emails{{/join}}", ctx, equalTo("john@smith.com,john.smith@email.com,jsmith@email.com")); diff --git a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java index c2ee89ad0e5bd..1e997eee9ff22 100644 --- a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java +++ b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateRequestXContentTests.java @@ -32,7 +32,7 @@ package org.opensearch.script.mustache; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -115,7 +115,7 @@ public void testToXContentWithInlineTemplate() throws IOException { XContentBuilder actualRequest = XContentFactory.contentBuilder(contentType); request.toXContent(actualRequest, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedRequest), BytesReferenceUtil.bytes(actualRequest), contentType); + assertToXContentEquivalent(BytesReference.bytes(expectedRequest), BytesReference.bytes(actualRequest), contentType); } public void testToXContentWithStoredTemplate() throws IOException { @@ -145,7 +145,7 @@ public void testToXContentWithStoredTemplate() throws IOException { XContentBuilder actualRequest = XContentFactory.contentBuilder(contentType); request.toXContent(actualRequest, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedRequest), BytesReferenceUtil.bytes(actualRequest), contentType); + assertToXContentEquivalent(BytesReference.bytes(expectedRequest), BytesReference.bytes(actualRequest), contentType); } public void testFromXContentWithEmbeddedTemplate() throws Exception { diff --git a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java index 48735b176e321..642625f932155 100644 --- a/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java +++ b/modules/lang-mustache/src/test/java/org/opensearch/script/mustache/SearchTemplateResponseTests.java @@ -36,7 +36,6 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.action.search.ShardSearchFailure; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -104,7 +103,7 @@ private static BytesReference createSource() { .endObject() .endObject() .endObject(); - return BytesReferenceUtil.bytes(source); + return BytesReference.bytes(source); } catch (IOException e) { throw new RuntimeException(e); } @@ -162,7 +161,7 @@ public void testSourceToXContent() throws IOException { .endObject() .endObject() .endObject(); - response.setSource(BytesReferenceUtil.bytes(source)); + response.setSource(BytesReference.bytes(source)); XContentType contentType = randomFrom(XContentType.values()); XContentBuilder expectedResponse = XContentFactory.contentBuilder(contentType) @@ -179,7 +178,7 @@ public void testSourceToXContent() throws IOException { XContentBuilder actualResponse = XContentFactory.contentBuilder(contentType); response.toXContent(actualResponse, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedResponse), BytesReferenceUtil.bytes(actualResponse), contentType); + assertToXContentEquivalent(BytesReference.bytes(expectedResponse), BytesReference.bytes(actualResponse), contentType); } public void testSearchResponseToXContent() throws IOException { @@ -239,6 +238,6 @@ public void testSearchResponseToXContent() throws IOException { XContentBuilder actualResponse = XContentFactory.contentBuilder(contentType); response.toXContent(actualResponse, ToXContent.EMPTY_PARAMS); - assertToXContentEquivalent(BytesReferenceUtil.bytes(expectedResponse), BytesReferenceUtil.bytes(actualResponse), contentType); + assertToXContentEquivalent(BytesReference.bytes(expectedResponse), BytesReference.bytes(actualResponse), contentType); } } diff --git a/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java index 5e4f045b8f047..18f854b3d1ea2 100644 --- a/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java @@ -63,7 +63,6 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -165,7 +164,7 @@ static class ContextSetup implements Writeable, ToXContentObject { PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> { try (XContentBuilder b = XContentBuilder.builder(p.contentType().xContent())) { b.copyCurrentStructure(p); - return BytesReferenceUtil.bytes(b); + return BytesReference.bytes(b); } }, DOCUMENT_FIELD); PARSER.declareObject( diff --git a/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java b/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java index 4335cadc48d52..baa43625054aa 100644 --- a/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java +++ b/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteRequestTests.java @@ -36,7 +36,6 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContent; @@ -76,7 +75,7 @@ public final void testFromXContent() throws Exception { try (XContentBuilder builder = XContentBuilder.builder(xContent)) { builder.value(testInstance); - StreamInput instanceInput = BytesReferenceUtil.bytes(builder).streamInput(); + StreamInput instanceInput = BytesReference.bytes(builder).streamInput(); try (XContentParser parser = xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, instanceInput)) { PainlessExecuteAction.Request result = PainlessExecuteAction.Request.parse(parser); assertThat(result, equalTo(testInstance)); @@ -126,7 +125,7 @@ private static ContextSetup randomContextSetup() { XContentBuilder xContentBuilder = XContentBuilder.builder(xContentType.xContent()); xContentBuilder.startObject(); xContentBuilder.endObject(); - doc = BytesReferenceUtil.bytes(xContentBuilder); + doc = BytesReference.bytes(xContentBuilder); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java index dde0a75e5d8ea..63487fd7baa89 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/RankFeatureMetaFieldMapperTests.java @@ -35,7 +35,6 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -89,7 +88,7 @@ public void testDocumentParsingFailsOnMetaField() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject()); DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); String rfMetaField = RankFeatureMetaFieldMapper.CONTENT_TYPE; - BytesReference bytes = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(rfMetaField, 0).endObject()); + BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(rfMetaField, 0).endObject()); MapperParsingException e = expectThrows( MapperParsingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON)) diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java index 5360c90b1766d..2662605cbfe5b 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -35,7 +35,7 @@ import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -135,7 +135,7 @@ public void testNotIndexed() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), XContentType.JSON ) ); @@ -156,7 +156,7 @@ public void testNoDocValues() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), XContentType.JSON ) ); @@ -177,7 +177,7 @@ public void testStore() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()), XContentType.JSON ) ); @@ -200,7 +200,7 @@ public void testCoerce() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), XContentType.JSON ) ); @@ -219,7 +219,7 @@ public void testCoerce() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()), XContentType.JSON ) ); @@ -243,7 +243,7 @@ private void doTestIgnoreMalformed(Object value, String exceptionMessageContains new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), XContentType.JSON ) ); @@ -257,7 +257,7 @@ private void doTestIgnoreMalformed(Object value, String exceptionMessageContains new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()), XContentType.JSON ) ); @@ -272,7 +272,7 @@ public void testNullValue() throws IOException { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), XContentType.JSON ) ); @@ -285,7 +285,7 @@ public void testNullValue() throws IOException { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()), XContentType.JSON ) ); diff --git a/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java b/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java index 4206e19a91acf..53e9495b707fe 100644 --- a/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java +++ b/modules/parent-join/src/test/java/org/opensearch/join/mapper/ParentJoinFieldMapperTests.java @@ -33,8 +33,8 @@ package org.opensearch.join.mapper; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -80,12 +80,7 @@ public void testSingleLevel() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse( - new SourceToParse( - "test", - "0", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().endObject()), - XContentType.JSON - ) + new SourceToParse("test", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON) ); assertNull(doc.rootDoc().getBinaryValue("join_field")); @@ -94,7 +89,7 @@ public void testSingleLevel() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), XContentType.JSON ) ); @@ -106,7 +101,7 @@ public void testSingleLevel() throws Exception { new SourceToParse( "test", "2", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -129,7 +124,7 @@ public void testSingleLevel() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), XContentType.JSON ) ) @@ -158,7 +153,7 @@ public void testParentIdSpecifiedAsNumber() throws Exception { new SourceToParse( "test", "2", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -177,7 +172,7 @@ public void testParentIdSpecifiedAsNumber() throws Exception { new SourceToParse( "test", "2", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -216,12 +211,7 @@ public void testMultipleLevels() throws Exception { // Doc without join ParsedDocument doc = docMapper.parse( - new SourceToParse( - "test", - "0", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().endObject()), - XContentType.JSON - ) + new SourceToParse("test", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON) ); assertNull(doc.rootDoc().getBinaryValue("join_field")); @@ -230,7 +220,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), XContentType.JSON ) ); @@ -242,7 +232,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "2", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -266,7 +256,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "2", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "child").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "child").endObject()), XContentType.JSON, "1" ) @@ -281,7 +271,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "2", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -301,7 +291,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "3", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("join_field") @@ -324,7 +314,7 @@ public void testMultipleLevels() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), XContentType.JSON ) ) diff --git a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java index 16fe05ca562b9..a0b04f62a84b6 100644 --- a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java @@ -41,7 +41,6 @@ import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.DistanceUnit; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -124,13 +123,13 @@ public void testPercolatorQuery() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().endObject()); + BytesReference source = BytesReference.bytes(jsonBuilder().startObject().endObject()); logger.info("percolating empty doc"); SearchResponse response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); logger.info("percolating doc with 1 field"); response = client().prepareSearch() .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) @@ -142,7 +141,7 @@ public void testPercolatorQuery() throws Exception { assertThat(response.getHits().getAt(1).getId(), equalTo("2")); assertThat(response.getHits().getAt(1).getFields().get("_percolator_document_slot").getValue(), equalTo(0)); - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()); logger.info("percolating doc with 2 fields"); response = client().prepareSearch() .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) @@ -162,8 +161,8 @@ public void testPercolatorQuery() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()) + BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject()) ), XContentType.JSON ) @@ -267,44 +266,44 @@ public void testPercolatorRangeQueries() throws Exception { client().admin().indices().prepareRefresh().get(); // Test long range: - BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", 12).endObject()); + BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("field1", 12).endObject()); SearchResponse response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); logger.info("response={}", response); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("3")); assertThat(response.getHits().getAt(1).getId(), equalTo("1")); - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", 11).endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field1", 11).endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); // Test double range: - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field2", 12).endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field2", 12).endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("6")); assertThat(response.getHits().getAt(1).getId(), equalTo("4")); - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field2", 11).endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field2", 11).endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("4")); // Test IP range: - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field3", "192.168.1.5").endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field3", "192.168.1.5").endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("9")); assertThat(response.getHits().getAt(1).getId(), equalTo("7")); - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field3", "192.168.1.4").endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field3", "192.168.1.4").endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("7")); // Test date range: - source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field4", "2016-05-15").endObject()); + source = BytesReference.bytes(jsonBuilder().startObject().field("field4", "2016-05-15").endObject()); response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)).get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("10")); @@ -352,7 +351,7 @@ public void testPercolatorGeoQueries() throws Exception { .get(); refresh(); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject().startObject("field1").field("lat", 52.20).field("lon", 4.51).endObject().endObject() ); SearchResponse response = client().prepareSearch() @@ -522,7 +521,7 @@ public void testPercolatorSpecificQueries() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .field("field1", "the quick brown fox jumps over the lazy dog") .field("field2", "the quick brown fox falls down into the well") @@ -583,7 +582,7 @@ public void testPercolatorQueryWithHighlighting() throws Exception { .actionGet(); client().admin().indices().prepareRefresh().get(); - BytesReference document = BytesReferenceUtil.bytes( + BytesReference document = BytesReference.bytes( jsonBuilder().startObject().field("field1", "The quick brown fox jumps over the lazy dog").endObject() ); SearchResponse searchResponse = client().prepareSearch() @@ -614,10 +613,10 @@ public void testPercolatorQueryWithHighlighting() throws Exception { equalTo("The quick brown fox jumps over the lazy dog") ); - BytesReference document1 = BytesReferenceUtil.bytes( + BytesReference document1 = BytesReference.bytes( jsonBuilder().startObject().field("field1", "The quick brown fox jumps").endObject() ); - BytesReference document2 = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "over the lazy dog").endObject()); + BytesReference document2 = BytesReference.bytes(jsonBuilder().startObject().field("field1", "over the lazy dog").endObject()); searchResponse = client().prepareSearch() .setQuery( boolQuery().should(new PercolateQueryBuilder("query", document1, XContentType.JSON).setName("query1")) @@ -655,10 +654,10 @@ public void testPercolatorQueryWithHighlighting() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()), - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) + BytesReference.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) ), XContentType.JSON ) @@ -710,8 +709,8 @@ public void testPercolatorQueryWithHighlighting() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()) + BytesReference.bytes(jsonBuilder().startObject().field("field1", "dog").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "fox").endObject()) ), XContentType.JSON ).setName("query1") @@ -720,8 +719,8 @@ public void testPercolatorQueryWithHighlighting() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) + BytesReference.bytes(jsonBuilder().startObject().field("field1", "jumps").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "brown fox").endObject()) ), XContentType.JSON ).setName("query2") @@ -898,7 +897,7 @@ public void testWithMultiplePercolatorFields() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("field", "value").endObject()); SearchResponse response = client().prepareSearch() .setQuery(new PercolateQueryBuilder(queryFieldName, source, XContentType.JSON)) .setIndices("test1") @@ -999,7 +998,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1026,7 +1025,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "notstark") @@ -1052,7 +1051,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("companyname", "notstark").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("companyname", "notstark").endObject()), XContentType.JSON ) ) @@ -1066,7 +1065,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { new PercolateQueryBuilder( "query", Arrays.asList( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1080,7 +1079,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .endArray() .endObject() ), - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1094,7 +1093,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .endArray() .endObject() ), - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -1158,7 +1157,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), XContentType.JSON ) ) @@ -1168,7 +1167,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(yamlBuilder().startObject().field("field1", "c").endObject()), + BytesReference.bytes(yamlBuilder().startObject().field("field1", "c").endObject()), XContentType.YAML ) ) @@ -1178,7 +1177,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "b c").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "b c").endObject()), XContentType.JSON ) ) @@ -1188,7 +1187,7 @@ public void testPercolatorQueryViaMultiSearch() throws Exception { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "d").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "d").endObject()), XContentType.JSON ) ) @@ -1247,7 +1246,7 @@ public void testDisallowExpensiveQueries() throws IOException { refresh(); // Execute with search.allow_expensive_queries = null => default value = false => success - BytesReference source = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); + BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()); SearchResponse response = client().prepareSearch() .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) .get(); @@ -1307,7 +1306,7 @@ public void testWrappedWithConstantScore() throws Exception { .setQuery( new PercolateQueryBuilder( "q", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), XContentType.JSON ) ) @@ -1318,7 +1317,7 @@ public void testWrappedWithConstantScore() throws Exception { .setQuery( new PercolateQueryBuilder( "q", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), XContentType.JSON ) ) @@ -1331,7 +1330,7 @@ public void testWrappedWithConstantScore() throws Exception { constantScoreQuery( new PercolateQueryBuilder( "q", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("d", "2020-02-01T15:00:00.000+11:00").endObject()), XContentType.JSON ) ) diff --git a/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java index 0f034c510b44b..498b58c8b6bba 100644 --- a/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java @@ -66,7 +66,6 @@ import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -393,7 +392,7 @@ private static BytesReference parseDocument(XContentParser parser) throws IOExce try (XContentBuilder builder = XContentFactory.jsonBuilder()) { builder.copyCurrentStructure(parser); builder.flush(); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java index 015e6e5b52df2..5014b838d94e3 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java @@ -44,7 +44,6 @@ import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.lucene.uid.Versions; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -320,7 +319,7 @@ private static BytesReference randomSource(Set usedFields) { XContentBuilder xContent = XContentFactory.jsonBuilder(); xContent.map(source); - return BytesReferenceUtil.bytes(xContent); + return BytesReference.bytes(xContent); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java index d8004d3364a1e..eb76229801479 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorFieldMapperTests.java @@ -58,6 +58,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.hash.MurmurHash3; @@ -67,7 +68,6 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.network.InetAddresses; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -559,7 +559,7 @@ public void testPercolatorFieldMapper() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -579,7 +579,7 @@ public void testPercolatorFieldMapper() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -596,7 +596,7 @@ public void testPercolatorFieldMapper() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -624,7 +624,7 @@ public void testStoringQueries() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, query).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, query).endObject()), XContentType.JSON ) ); @@ -642,7 +642,7 @@ public void testQueryWithRewrite() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()), XContentType.JSON ) ); @@ -666,7 +666,7 @@ public void testPercolatorFieldMapperUnMappedField() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder().startObject().field(fieldName, termQuery("unmapped_field", "value")).endObject() ), XContentType.JSON @@ -684,7 +684,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON ) ); @@ -696,7 +696,7 @@ public void testPercolatorFieldMapper_noQuery() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject()), XContentType.JSON ) ); @@ -758,7 +758,7 @@ public void testMultiplePercolatorFields() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject().field("query_field1", queryBuilder).field("query_field2", queryBuilder).endObject() ), XContentType.JSON @@ -800,7 +800,7 @@ public void testNestedPercolatorField() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject().startObject("object_field").field("query_field", queryBuilder).endObject().endObject() ), XContentType.JSON @@ -819,7 +819,7 @@ public void testNestedPercolatorField() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("object_field") .startObject() @@ -841,7 +841,7 @@ public void testNestedPercolatorField() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("object_field") .startObject() @@ -948,7 +948,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) @@ -995,7 +995,7 @@ public void testImplicitlySetDefaultScriptLang() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .rawField(fieldName, new BytesArray(Strings.toString(query)).streamInput(), query.contentType()) @@ -1089,7 +1089,7 @@ public void testDuplicatedClauses() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), XContentType.JSON ) ); @@ -1114,7 +1114,7 @@ public void testDuplicatedClauses() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), XContentType.JSON ) ); @@ -1142,7 +1142,7 @@ public void testDuplicatedClauses() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()), XContentType.JSON ) ); diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java index c8bd50ef55dab..1e85e1ad18314 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java @@ -37,7 +37,6 @@ import org.opensearch.action.support.WriteRequest; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -115,7 +114,7 @@ public void testPercolateScriptQuery() throws IOException { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "b").endObject()), XContentType.JSON ) ) @@ -175,7 +174,7 @@ public void testPercolateQueryWithNestedDocuments_doNotLeakBitsetCacheEntries() .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("companyname", "stark") @@ -270,7 +269,7 @@ public void testPercolateQueryWithNestedDocuments_doLeakFieldDataCacheEntries() doc.endObject(); for (int i = 0; i < 32; i++) { SearchResponse response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", BytesReferenceUtil.bytes(doc), XContentType.JSON)) + .setQuery(new PercolateQueryBuilder("query", BytesReference.bytes(doc), XContentType.JSON)) .addSort("_doc", SortOrder.ASC) .get(); assertHitCount(response, 1); @@ -293,7 +292,7 @@ public void testMapUnmappedFieldAsText() throws IOException { .setQuery( new PercolateQueryBuilder( "query", - BytesReferenceUtil.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), + BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").endObject()), XContentType.JSON ) ) @@ -346,7 +345,7 @@ public void testRangeQueriesWithNow() throws Exception { long[] currentTime = new long[] { System.currentTimeMillis() }; QueryShardContext queryShardContext = indexService.newQueryShardContext(0, searcher, () -> currentTime[0], null); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject().field("field1", "value").field("field2", currentTime[0]).endObject() ); QueryBuilder queryBuilder = new PercolateQueryBuilder("query", source, XContentType.JSON); @@ -354,9 +353,7 @@ public void testRangeQueriesWithNow() throws Exception { assertThat(searcher.count(query), equalTo(3)); currentTime[0] = currentTime[0] + 10800000; // + 3 hours - source = BytesReferenceUtil.bytes( - jsonBuilder().startObject().field("field1", "value").field("field2", currentTime[0]).endObject() - ); + source = BytesReference.bytes(jsonBuilder().startObject().field("field1", "value").field("field2", currentTime[0]).endObject()); queryBuilder = new PercolateQueryBuilder("query", source, XContentType.JSON); query = queryBuilder.toQuery(queryShardContext); assertThat(searcher.count(query), equalTo(3)); diff --git a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java index 1819e7d1369c8..b52c1c1897086 100644 --- a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java +++ b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalResponseTests.java @@ -44,7 +44,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -179,7 +178,7 @@ public void testToXContent() throws IOException { Collections.singletonMap("beer_query", new ParsingException(new XContentLocation(0, 0), "someMsg")) ); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); - String xContent = BytesReferenceUtil.bytes(response.toXContent(builder, ToXContent.EMPTY_PARAMS)).utf8ToString(); + String xContent = BytesReference.bytes(response.toXContent(builder, ToXContent.EMPTY_PARAMS)).utf8ToString(); assertEquals( ("{" + " \"metric_score\": 0.123," diff --git a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java index 87e0cf8765f76..e4a21b61052cd 100644 --- a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java +++ b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/RankEvalSpecTests.java @@ -35,7 +35,6 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -143,7 +142,7 @@ static RankEvalSpec createTestItem() { public void testXContentRoundtrip() throws IOException { RankEvalSpec testItem = createTestItem(); XContentBuilder shuffled = shuffleXContent(testItem.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(shuffled))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(shuffled))) { RankEvalSpec parsedItem = RankEvalSpec.parse(parser); assertNotSame(testItem, parsedItem); assertEquals(testItem, parsedItem); diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java index 836fa5249f4c1..7367182150aea 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/AbstractBulkByQueryRestHandler.java @@ -34,8 +34,8 @@ import org.opensearch.action.ActionType; import org.opensearch.action.search.SearchRequest; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -121,7 +121,7 @@ private XContentParser extractRequestSpecificFields(RestRequest restRequest, Map .createParser( parser.getXContentRegistry(), parser.getDeprecationHandler(), - BytesReferenceUtil.bytes(builder.map(body)).streamInput() + BytesReference.bytes(builder.map(body)).streamInput() ); } } diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java index c82496ee44a4a..a5107597e4113 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/Reindexer.java @@ -57,8 +57,8 @@ import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.lucene.uid.Versions; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -390,7 +390,7 @@ protected RequestWrapper buildRequest(ScrollableHitSource.Hit doc) ) { parser.nextToken(); builder.copyCurrentStructure(parser); - index.source(BytesReferenceUtil.bytes(builder), builder.contentType()); + index.source(BytesReference.bytes(builder), builder.contentType()); } catch (IOException e) { throw new UncheckedIOException( "failed to convert hit from " + sourceXContentType + " to " + mainRequestXContentType, diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java index 9f982cf10e69a..5a4674e146585 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java @@ -35,7 +35,7 @@ import org.apache.lucene.search.TotalHits; import org.opensearch.LegacyESVersion; import org.opensearch.Version; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.collect.Tuple; @@ -92,7 +92,7 @@ private RemoteResponseParsers() {} try (XContentBuilder b = XContentBuilder.builder(s.xContent())) { b.copyCurrentStructure(p); // a hack but this lets us get the right xcontent type to go with the source - return new Tuple<>(BytesReferenceUtil.bytes(b), s); + return new Tuple<>(BytesReference.bytes(b), s); } } catch (IOException e) { throw new ParsingException(p.getTokenLocation(), "[hit] failed to parse [_source]", e); diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java index a72f61aaeba43..4b9aa0ac2ce62 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.reindex; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -74,7 +74,7 @@ public void testPipelineQueryParameterIsError() throws IOException { body.endObject(); } body.endObject(); - request.withContent(BytesReferenceUtil.bytes(body), XContentType.fromMediaType(body.contentType())); + request.withContent(BytesReference.bytes(body), XContentType.fromMediaType(body.contentType())); } request.withParams(singletonMap("pipeline", "doesn't matter")); Exception e = expectThrows( diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java index 1e59c34764734..7deb8faa03af6 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/FilterQueryRequestProcessor.java @@ -9,7 +9,7 @@ package org.opensearch.search.pipeline.common; import org.opensearch.action.search.SearchRequest; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -105,7 +105,7 @@ public FilterQueryRequestProcessor create( ) throws Exception { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); + InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java index 22fdebc3b9573..4c40dda5928f0 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.java @@ -13,7 +13,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.common.document.DocumentField; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.XContentBuilder; @@ -114,7 +113,7 @@ public SearchResponse processResponse(SearchRequest request, SearchResponse resp XContentBuilder builder = XContentBuilder.builder(typeAndSourceMap.v1().xContent()); builder.map(sourceAsMap); - hit.sourceRef(BytesReferenceUtil.bytes(builder)); + hit.sourceRef(BytesReference.bytes(builder)); } } diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java index db99bd2baf4d5..015411e0701a4 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/ScriptRequestProcessor.java @@ -11,7 +11,7 @@ import org.opensearch.action.search.SearchRequest; import org.opensearch.common.Nullable; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -157,7 +157,7 @@ public ScriptRequestProcessor create( ) throws Exception { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); + InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java index dc71d64eb7233..4e4648a87fbfc 100644 --- a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java @@ -38,7 +38,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -66,7 +65,7 @@ public void testSizeEnabled() throws Exception { IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true"); DocumentMapper docMapper = service.mapperService().documentMapper(); - BytesReference source = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); ParsedDocument doc = docMapper.parse(new SourceToParse("test", "1", source, XContentType.JSON)); boolean stored = false; @@ -83,7 +82,7 @@ public void testSizeDisabled() throws Exception { IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=false"); DocumentMapper docMapper = service.mapperService().documentMapper(); - BytesReference source = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); ParsedDocument doc = docMapper.parse(new SourceToParse("test", "1", source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); @@ -93,7 +92,7 @@ public void testSizeNotSet() throws Exception { IndexService service = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME); DocumentMapper docMapper = service.mapperService().documentMapper(); - BytesReference source = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); + BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); ParsedDocument doc = docMapper.parse(new SourceToParse("test", "1", source, XContentType.JSON)); assertThat(doc.rootDoc().getField("_size"), nullValue()); diff --git a/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java b/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java index b9bf44eca4681..1c89c0df962ee 100644 --- a/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java +++ b/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java @@ -41,7 +41,6 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.test.OpenSearchTestCase; @@ -186,7 +185,7 @@ private byte[] serviceAccountFileContent(String projectId) throws Exception { .field("client_email", "integration_test@appspot.gserviceaccount.com") .field("client_id", "client_id") .endObject(); - return BytesReference.toBytes(BytesReferenceUtil.bytes(serviceAccountBuilder)); + return BytesReference.toBytes(BytesReference.bytes(serviceAccountBuilder)); } public void testToTimeout() { diff --git a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java index 9fbd9fa374a47..ec8d02a8c57b7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java @@ -45,7 +45,7 @@ import org.opensearch.action.support.replication.ReplicationRequest; import org.opensearch.action.update.UpdateRequest; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.IngestTestPlugin; @@ -183,7 +183,7 @@ private void createSamplePipeline(String pipelineId) throws IOException, Executi AcknowledgedResponse acknowledgedResponse = client().admin() .cluster() - .putPipeline(new PutPipelineRequest(pipelineId, BytesReferenceUtil.bytes(pipeline), XContentType.JSON)) + .putPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(pipeline), XContentType.JSON)) .get(); assertTrue(acknowledgedResponse.isAcknowledged()); diff --git a/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java b/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java index c05e1cbea7b79..2f811d4a901bf 100644 --- a/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java @@ -49,7 +49,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.engine.VersionConflictEngineException; @@ -607,7 +606,7 @@ public void testGetFieldsComplexField() throws Exception { ) ); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .startArray("field1") .startObject() diff --git a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java index b02db70b70f0e..522938003838b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java @@ -53,7 +53,6 @@ import org.opensearch.client.Requests; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; @@ -90,7 +89,7 @@ protected Collection> nodePlugins() { } public void testSimulate() throws Exception { - BytesReference pipelineSource = BytesReferenceUtil.bytes( + BytesReference pipelineSource = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -107,7 +106,7 @@ public void testSimulate() throws Exception { assertThat(getResponse.pipelines().size(), equalTo(1)); assertThat(getResponse.pipelines().get(0).getId(), equalTo("_id")); - BytesReference bytes = BytesReferenceUtil.bytes( + BytesReference bytes = BytesReference.bytes( jsonBuilder().startObject() .startArray("docs") .startObject() @@ -150,7 +149,7 @@ public void testSimulate() throws Exception { public void testBulkWithIngestFailures() throws Exception { createIndex("index"); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -201,7 +200,7 @@ public void testBulkWithIngestFailures() throws Exception { public void testBulkWithUpsert() throws Exception { createIndex("index"); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -236,7 +235,7 @@ public void testBulkWithUpsert() throws Exception { } public void test() throws Exception { - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -279,7 +278,7 @@ public void test() throws Exception { } public void testPutWithPipelineFactoryError() throws Exception { - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -304,7 +303,7 @@ public void testPutWithPipelineFactoryError() throws Exception { public void testWithDedicatedClusterManager() throws Exception { String clusterManagerOnlyNode = internalCluster().startClusterManagerOnlyNode(); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") @@ -341,7 +340,7 @@ public void testPipelineOriginHeader() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReferenceUtil.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReference.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -358,7 +357,7 @@ public void testPipelineOriginHeader() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReferenceUtil.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReference.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -374,7 +373,7 @@ public void testPipelineOriginHeader() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReferenceUtil.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReference.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } @@ -414,7 +413,7 @@ public void testPipelineProcessorOnFailure() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReferenceUtil.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("1", BytesReference.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -431,7 +430,7 @@ public void testPipelineProcessorOnFailure() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReferenceUtil.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("2", BytesReference.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } { @@ -447,7 +446,7 @@ public void testPipelineProcessorOnFailure() throws Exception { source.endArray(); } source.endObject(); - PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReferenceUtil.bytes(source), XContentType.JSON); + PutPipelineRequest putPipelineRequest = new PutPipelineRequest("3", BytesReference.bytes(source), XContentType.JSON); client().admin().cluster().putPipeline(putPipelineRequest).get(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java index d5d4e246dae79..a615cceffb5df 100644 --- a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java @@ -35,7 +35,6 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.node.NodeService; import org.opensearch.plugins.Plugin; @@ -59,7 +58,7 @@ public class IngestProcessorNotInstalledOnAllNodesIT extends OpenSearchIntegTest private volatile boolean installPlugin; public IngestProcessorNotInstalledOnAllNodesIT() throws IOException { - pipelineSource = BytesReferenceUtil.bytes( + pipelineSource = BytesReference.bytes( jsonBuilder().startObject() .startArray("processors") .startObject() diff --git a/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java b/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java index 93c2029615d45..c9d18e64ca038 100644 --- a/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java @@ -41,7 +41,6 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.search.fetch.subphase.FetchSourceContext; import org.opensearch.test.OpenSearchIntegTestCase; @@ -149,7 +148,7 @@ public void testThatMgetShouldWorkWithAliasRouting() throws IOException { @SuppressWarnings("unchecked") public void testThatSourceFilteringIsSupported() throws Exception { assertAcked(prepareCreate("test").addAlias(new Alias("alias"))); - BytesReference sourceBytesRef = BytesReferenceUtil.bytes( + BytesReference sourceBytesRef = BytesReference.bytes( jsonBuilder().startObject() .array("field", "1", "2") .startObject("included") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java index 4cc509f3e8a0e..9b40df5f19b9f 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java @@ -35,7 +35,6 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -70,7 +69,7 @@ public void testWrapperQueryIsRewritten() throws IOException { builder.endObject(); } builder.endObject(); - bytesReference = BytesReferenceUtil.bytes(builder); + bytesReference = BytesReference.bytes(builder); } FiltersAggregationBuilder builder = new FiltersAggregationBuilder( "titles", diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java index 9dd2bd7380877..7945f1f4274fb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java @@ -44,7 +44,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.time.DateFormatter; import org.opensearch.common.time.DateUtils; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -893,7 +892,7 @@ public void testGetFieldsComplexField() throws Exception { ) .get(); - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( jsonBuilder().startObject() .startArray("field1") .startObject() diff --git a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java index 1efc18c1e78a8..3444ddbca9e65 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java @@ -57,7 +57,6 @@ import org.opensearch.common.geo.builders.PointBuilder; import org.opensearch.common.geo.builders.PolygonBuilder; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -243,7 +242,7 @@ public void testShapeRelations() throws Exception { .polygon( new PolygonBuilder(new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()) ); - BytesReference data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", polygon).endObject()); + BytesReference data = BytesReference.bytes(jsonBuilder().startObject().field("area", polygon).endObject()); client().prepareIndex("shapes").setId("1").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); @@ -307,7 +306,7 @@ public void testShapeRelations() throws Exception { new LineStringBuilder(new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()) ); - data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", inverse).endObject()); + data = BytesReference.bytes(jsonBuilder().startObject().field("area", inverse).endObject()); client().prepareIndex("shapes").setId("2").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); @@ -346,7 +345,7 @@ public void testShapeRelations() throws Exception { new CoordinatesBuilder().coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close() ); - data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", builder).endObject()); + data = BytesReference.bytes(jsonBuilder().startObject().field("area", builder).endObject()); client().prepareIndex("shapes").setId("1").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); @@ -359,7 +358,7 @@ public void testShapeRelations() throws Exception { ) ); - data = BytesReferenceUtil.bytes(jsonBuilder().startObject().field("area", builder).endObject()); + data = BytesReference.bytes(jsonBuilder().startObject().field("area", builder).endObject()); client().prepareIndex("shapes").setId("1").setSource(data, XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java b/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java index a552e0c1b253c..a1ee8017894da 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/scroll/SearchScrollIT.java @@ -41,9 +41,9 @@ import org.opensearch.action.search.ShardSearchFailure; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Priority; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -798,7 +798,7 @@ public void testRestartDataNodesDuringScrollSearch() throws Exception { private void assertToXContentResponse(ClearScrollResponse response, boolean succeed, int numFreed) throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); - Map map = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + Map map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); assertThat(map.get("succeeded"), is(succeed)); assertThat(map.get("num_freed"), equalTo(numFreed)); } diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java index e3741932cd674..ea1635b1d8053 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java @@ -42,7 +42,6 @@ import org.opensearch.action.ingest.GetPipelineResponse; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.IngestTestPlugin; @@ -105,7 +104,7 @@ public void testIncludeGlobalState() throws Exception { if (testPipeline) { logger.info("--> creating test pipeline"); - BytesReference pipelineSource = BytesReferenceUtil.bytes( + BytesReference pipelineSource = BytesReference.bytes( jsonBuilder().startObject() .field("description", "my_pipeline") .startArray("processors") diff --git a/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java b/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java index 3365aad425781..1c5d0c84a9a2f 100644 --- a/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/update/UpdateNoopIT.java @@ -34,7 +34,7 @@ import org.opensearch.action.update.UpdateRequestBuilder; import org.opensearch.action.update.UpdateResponse; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.test.OpenSearchIntegTestCase; @@ -323,7 +323,7 @@ private void updateAndCheckSource(long expectedSeqNo, long expectedVersion, XCon private void updateAndCheckSource(long expectedSeqNo, long expectedVersion, Boolean detectNoop, XContentBuilder xContentBuilder) { UpdateResponse updateResponse = update(detectNoop, expectedSeqNo, expectedVersion, xContentBuilder); - assertEquals(updateResponse.getGetResult().sourceRef().utf8ToString(), BytesReferenceUtil.bytes(xContentBuilder).utf8ToString()); + assertEquals(updateResponse.getGetResult().sourceRef().utf8ToString(), BytesReference.bytes(xContentBuilder).utf8ToString()); } private UpdateResponse update(Boolean detectNoop, long expectedSeqNo, long expectedVersion, XContentBuilder xContentBuilder) { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java index a7385c57d4b91..738c8a9d514c9 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/delete/ClusterDeleteWeightedRoutingRequest.java @@ -18,7 +18,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.DeprecationHandler; @@ -90,7 +89,7 @@ public ClusterDeleteWeightedRoutingRequest source(Map source) { } XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - setRequestBody(BytesReferenceUtil.bytes(builder), builder.contentType()); + setRequestBody(BytesReference.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java index 2a3dc4053f82a..fe95b614a02d1 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/shards/routing/weighted/put/ClusterPutWeightedRoutingRequest.java @@ -19,7 +19,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.DeprecationHandler; @@ -87,7 +86,7 @@ public void setWeightedRouting(Map source) { } XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - setWeightedRouting(BytesReferenceUtil.bytes(builder), builder.contentType()); + setWeightedRouting(BytesReference.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java index 21fb7a49d0dd3..0226b20b5bf34 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java @@ -39,10 +39,10 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; @@ -182,7 +182,7 @@ public static int metadataSize(Map userMetadata) { } try (XContentBuilder builder = XContentFactory.jsonBuilder()) { builder.value(userMetadata); - int size = BytesReferenceUtil.bytes(builder).length(); + int size = BytesReference.bytes(builder).length(); return size; } catch (IOException e) { // This should not be possible as we are just rendering the xcontent in memory diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java index 45bae32f8c0c6..b9c11a003c459 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java @@ -48,7 +48,6 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -316,7 +315,7 @@ public CreateIndexRequest mapping(BytesReference source, MediaType mediaType) { * @param source The mapping source */ public CreateIndexRequest mapping(XContentBuilder source) { - return mapping(BytesReferenceUtil.bytes(source), source.contentType()); + return mapping(BytesReference.bytes(source), source.contentType()); } /** @@ -377,7 +376,7 @@ public CreateIndexRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReferenceUtil.bytes(builder)); + return aliases(BytesReference.bytes(builder)); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -387,7 +386,7 @@ public CreateIndexRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public CreateIndexRequest aliases(XContentBuilder source) { - return aliases(BytesReferenceUtil.bytes(source)); + return aliases(BytesReference.bytes(source)); } /** @@ -445,7 +444,7 @@ public CreateIndexRequest source(String source, MediaType mediaType) { * Sets the settings and mappings as a single source. */ public CreateIndexRequest source(XContentBuilder source) { - return source(BytesReferenceUtil.bytes(source), source.contentType()); + return source(BytesReference.bytes(source), source.contentType()); } /** diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java index 4a75b96354c69..a9e5e8f1484b8 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java @@ -34,7 +34,6 @@ import org.opensearch.Version; import org.opensearch.action.ActionResponse; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -196,7 +195,7 @@ public static class FieldMappingMetadata implements ToXContentFragment { PARSER.declareField(optionalConstructorArg(), (p, c) -> p.text(), FULL_NAME, ObjectParser.ValueType.STRING); PARSER.declareField(optionalConstructorArg(), (p, c) -> { final XContentBuilder jsonBuilder = jsonBuilder().copyCurrentStructure(p); - final BytesReference bytes = BytesReferenceUtil.bytes(jsonBuilder); + final BytesReference bytes = BytesReference.bytes(jsonBuilder); return bytes; }, MAPPING, ObjectParser.ValueType.OBJECT); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java index b0cae3585410b..200c12fd90a72 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -44,7 +44,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -291,7 +290,7 @@ public static XContentBuilder simpleMapping(String... source) { * The mapping source definition. */ public PutMappingRequest source(XContentBuilder mappingBuilder) { - return source(BytesReferenceUtil.bytes(mappingBuilder), mappingBuilder.contentType()); + return source(BytesReference.bytes(mappingBuilder), mappingBuilder.contentType()); } /** @@ -301,7 +300,7 @@ public PutMappingRequest source(Map mappingSource) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(mappingSource); - return source(BytesReferenceUtil.bytes(builder), builder.contentType()); + return source(BytesReference.bytes(builder), builder.contentType()); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + mappingSource + "]", e); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index e0cb579004071..0ab896bf87750 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -48,7 +48,6 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -272,7 +271,7 @@ public PutIndexTemplateRequest mapping(String source, MediaType mediaType) { * @param source The mapping source */ public PutIndexTemplateRequest mapping(XContentBuilder source) { - return mapping(BytesReferenceUtil.bytes(source), source.contentType()); + return mapping(BytesReference.bytes(source), source.contentType()); } /** @@ -324,7 +323,7 @@ public String mappings() { */ public PutIndexTemplateRequest source(XContentBuilder templateBuilder) { try { - return source(BytesReferenceUtil.bytes(templateBuilder), templateBuilder.contentType()); + return source(BytesReference.bytes(templateBuilder), templateBuilder.contentType()); } catch (Exception e) { throw new IllegalArgumentException("Failed to build json for template request", e); } @@ -428,7 +427,7 @@ public PutIndexTemplateRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - return aliases(BytesReferenceUtil.bytes(builder)); + return aliases(BytesReference.bytes(builder)); } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); } @@ -438,7 +437,7 @@ public PutIndexTemplateRequest aliases(Map source) { * Sets the aliases that will be associated with the index when it gets created */ public PutIndexTemplateRequest aliases(XContentBuilder source) { - return aliases(BytesReferenceUtil.bytes(source)); + return aliases(BytesReference.bytes(source)); } /** diff --git a/server/src/main/java/org/opensearch/action/index/IndexRequest.java b/server/src/main/java/org/opensearch/action/index/IndexRequest.java index ffe9998033084..1cce14ef447f5 100644 --- a/server/src/main/java/org/opensearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/opensearch/action/index/IndexRequest.java @@ -54,7 +54,6 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.lucene.uid.Versions; import org.opensearch.common.unit.ByteSizeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -397,7 +396,7 @@ public IndexRequest source(String source, XContentType xContentType) { * Sets the content source to index. */ public IndexRequest source(XContentBuilder sourceBuilder) { - return source(BytesReferenceUtil.bytes(sourceBuilder), sourceBuilder.contentType()); + return source(BytesReference.bytes(sourceBuilder), sourceBuilder.contentType()); } /** diff --git a/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java b/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java index c79aa6bb6f64b..6890252cec014 100644 --- a/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java +++ b/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java @@ -34,9 +34,9 @@ import org.opensearch.action.ActionResponse; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.StatusToXContentObject; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -128,7 +128,7 @@ public static GetPipelineResponse fromXContent(XContentParser parser) throws IOE contentBuilder.generator().copyCurrentStructure(parser); PipelineConfiguration pipeline = new PipelineConfiguration( pipelineId, - BytesReferenceUtil.bytes(contentBuilder), + BytesReference.bytes(contentBuilder), contentBuilder.contentType() ); pipelines.add(pipeline); diff --git a/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java b/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java index 00587ad180af0..4fd86febcb0ae 100644 --- a/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java +++ b/server/src/main/java/org/opensearch/action/search/GetSearchPipelineResponse.java @@ -10,9 +10,9 @@ import org.opensearch.action.ActionResponse; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.StatusToXContentObject; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -82,7 +82,7 @@ public static GetSearchPipelineResponse fromXContent(XContentParser parser) thro contentBuilder.generator().copyCurrentStructure(parser); PipelineConfiguration pipeline = new PipelineConfiguration( pipelineId, - BytesReferenceUtil.bytes(contentBuilder), + BytesReference.bytes(contentBuilder), contentBuilder.contentType() ); pipelines.add(pipeline); diff --git a/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java b/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java index 634338e418b50..d1095840189aa 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchRequest.java @@ -42,7 +42,6 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.logging.DeprecationLogger; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -329,7 +328,7 @@ public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, for (SearchRequest request : multiSearchRequest.requests()) { try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { writeSearchRequestParams(request, xContentBuilder); - BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); + BytesReference.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { @@ -339,7 +338,7 @@ public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, xContentBuilder.startObject(); xContentBuilder.endObject(); } - BytesReferenceUtil.bytes(xContentBuilder).writeTo(output); + BytesReference.bytes(xContentBuilder).writeTo(output); } output.write(xContent.streamSeparator()); } diff --git a/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java b/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java index 911061d8737fb..2a170dec776a4 100644 --- a/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java +++ b/server/src/main/java/org/opensearch/action/termvectors/TermVectorsRequest.java @@ -40,7 +40,6 @@ import org.opensearch.action.get.MultiGetRequest; import org.opensearch.action.support.single.shard.SingleShardRequest; import org.opensearch.common.Nullable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; @@ -294,7 +293,7 @@ public XContentType xContentType() { * Sets an artificial document from which term vectors are requested for. */ public TermVectorsRequest doc(XContentBuilder documentBuilder) { - return this.doc(BytesReferenceUtil.bytes(documentBuilder), true, documentBuilder.contentType()); + return this.doc(BytesReference.bytes(documentBuilder), true, documentBuilder.contentType()); } /** diff --git a/server/src/main/java/org/opensearch/action/update/UpdateHelper.java b/server/src/main/java/org/opensearch/action/update/UpdateHelper.java index ef217f3c5e9b0..47a764f9effa3 100644 --- a/server/src/main/java/org/opensearch/action/update/UpdateHelper.java +++ b/server/src/main/java/org/opensearch/action/update/UpdateHelper.java @@ -44,7 +44,6 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -370,7 +369,7 @@ public static GetResult extractGetResult( BytesStreamOutput streamOutput = new BytesStreamOutput(initialCapacity); try (XContentBuilder builder = new XContentBuilder(sourceContentType.xContent(), streamOutput)) { builder.value(value); - sourceFilteredAsBytes = BytesReferenceUtil.bytes(builder); + sourceFilteredAsBytes = BytesReference.bytes(builder); } } catch (IOException e) { throw new OpenSearchException("Error filtering source", e); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java index 1d4bf25babef7..72b6380e78a1e 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java @@ -36,10 +36,10 @@ import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; import org.opensearch.common.Nullable; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -317,7 +317,7 @@ public Builder filter(Map filter) { } try { XContentBuilder builder = XContentFactory.jsonBuilder().map(filter); - this.filter = new CompressedXContent(BytesReferenceUtil.bytes(builder)); + this.filter = new CompressedXContent(BytesReference.bytes(builder)); return this; } catch (IOException e) { throw new OpenSearchGenerationException("Failed to build json for alias request", e); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java index 5b63ab3e27d73..23d2a1667afaf 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MappingMetadata.java @@ -35,10 +35,10 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -89,7 +89,7 @@ public MappingMetadata(String type, Map mapping) { this.type = type; try { XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping); - this.source = new CompressedXContent(BytesReferenceUtil.bytes(mappingBuilder)); + this.source = new CompressedXContent(BytesReference.bytes(mappingBuilder)); } catch (IOException e) { throw new UncheckedIOException(e); // XContent exception, should never happen } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java index 8fefab67fa50a..76860e568f1a1 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java @@ -50,6 +50,7 @@ import org.opensearch.common.Priority; import org.opensearch.common.UUIDs; import org.opensearch.common.ValidationException; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.inject.Inject; import org.opensearch.common.logging.HeaderWarning; @@ -57,7 +58,6 @@ import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -1153,7 +1153,7 @@ public static List collectMappings(final ClusterState state, .map(mapping -> { try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { builder.value(mapping); - return new CompressedXContent(BytesReferenceUtil.bytes(builder)); + return new CompressedXContent(BytesReference.bytes(builder)); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/server/src/main/java/org/opensearch/common/Strings.java b/server/src/main/java/org/opensearch/common/Strings.java index cd9e2d1734232..0bec840a15f40 100644 --- a/server/src/main/java/org/opensearch/common/Strings.java +++ b/server/src/main/java/org/opensearch/common/Strings.java @@ -36,7 +36,6 @@ import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.CollectionUtils; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; @@ -246,7 +245,7 @@ public static String toString(MediaType mediaType, ToXContent toXContent, ToXCon * @param xContentBuilder builder containing an object to converted to a string */ public static String toString(XContentBuilder xContentBuilder) { - return BytesReferenceUtil.bytes(xContentBuilder).utf8ToString(); + return BytesReference.bytes(xContentBuilder).utf8ToString(); } /** diff --git a/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java b/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java deleted file mode 100644 index c796ac95b38e5..0000000000000 --- a/server/src/main/java/org/opensearch/common/util/BytesReferenceUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.common.util; - -import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.io.stream.BytesStream; -import org.opensearch.core.xcontent.XContentBuilder; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; - -/** - * Server specific utilities for BytesReference objects - * - * @opensearch.internal - */ -public class BytesReferenceUtil { - /** - * Convert an {@link XContentBuilder} into a BytesReference. This method closes the builder, - * so no further fields may be added. - */ - public static BytesReference bytes(XContentBuilder xContentBuilder) { - xContentBuilder.close(); - OutputStream stream = xContentBuilder.getOutputStream(); - if (stream instanceof ByteArrayOutputStream) { - return new BytesArray(((ByteArrayOutputStream) stream).toByteArray()); - } else { - return ((BytesStream) stream).bytes(); - } - } -} diff --git a/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java b/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java index 12484c378b5f0..0859738478fc2 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java +++ b/server/src/main/java/org/opensearch/common/xcontent/JsonToStringXContentParser.java @@ -8,7 +8,7 @@ package org.opensearch.common.xcontent; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.AbstractXContentParser; import org.opensearch.core.xcontent.DeprecationHandler; @@ -70,7 +70,7 @@ public XContentParser parseObject() throws IOException { builder.field(this.fieldTypeName + VALUE_SUFFIX, valueList); builder.field(this.fieldTypeName + VALUE_AND_PATH_SUFFIX, valueAndPathList); builder.endObject(); - String jString = XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder), false, XContentType.JSON); + String jString = XContentHelper.convertToJson(BytesReference.bytes(builder), false, XContentType.JSON); return JsonXContent.jsonXContent.createParser(this.xContentRegistry, this.deprecationHandler, String.valueOf(jString)); } diff --git a/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java b/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java index 08fb014513d59..be98d1cf73515 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java +++ b/server/src/main/java/org/opensearch/common/xcontent/ObjectParserHelper.java @@ -33,7 +33,6 @@ package org.opensearch.common.xcontent; import org.opensearch.common.CheckedFunction; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.AbstractObjectParser; @@ -65,7 +64,7 @@ public void declareRawObject( final CheckedFunction bytesParser = p -> { try (XContentBuilder builder = JsonXContent.contentBuilder()) { builder.copyCurrentStructure(p); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } }; parser.declareField(consumer, bytesParser, field, ValueType.OBJECT); diff --git a/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java b/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java index b7c87a6d653ef..482549ae194bd 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java +++ b/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java @@ -39,7 +39,6 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.compress.Compressor; import org.opensearch.common.compress.CompressorFactory; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -521,7 +520,7 @@ public static BytesReference toXContent(ToXContent toXContent, XContentType xCon if (toXContent.isFragment()) { builder.endObject(); } - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } @@ -541,7 +540,7 @@ public static BytesReference toXContent(ToXContent toXContent, MediaType mediaTy if (toXContent.isFragment()) { builder.endObject(); } - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } @@ -586,6 +585,6 @@ public static BytesReference childBytes(XContentParser parser) throws IOExceptio } XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent()); builder.copyCurrentStructure(parser); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } diff --git a/server/src/main/java/org/opensearch/index/get/GetResult.java b/server/src/main/java/org/opensearch/index/get/GetResult.java index 5a18032b52686..a88294943c087 100644 --- a/server/src/main/java/org/opensearch/index/get/GetResult.java +++ b/server/src/main/java/org/opensearch/index/get/GetResult.java @@ -41,7 +41,6 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -379,7 +378,7 @@ public static GetResult fromXContentEmbedded(XContentParser parser, String index // the original document gets slightly modified: whitespaces or pretty printing are not preserved, // it all depends on the current builder settings builder.copyCurrentStructure(parser); - source = BytesReferenceUtil.bytes(builder); + source = BytesReference.bytes(builder); } } else if (FIELDS.equals(currentFieldName)) { while (parser.nextToken() != XContentParser.Token.END_OBJECT) { diff --git a/server/src/main/java/org/opensearch/index/get/ShardGetService.java b/server/src/main/java/org/opensearch/index/get/ShardGetService.java index 034722259aa76..08e2b32bded0e 100644 --- a/server/src/main/java/org/opensearch/index/get/ShardGetService.java +++ b/server/src/main/java/org/opensearch/index/get/ShardGetService.java @@ -50,7 +50,6 @@ import org.opensearch.common.lucene.uid.VersionsAndSeqNoResolver.DocIdAndVersion; import org.opensearch.common.metrics.CounterMetric; import org.opensearch.common.metrics.MeanMetric; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -379,7 +378,7 @@ private GetResult innerGetLoadFromStoredFields( sourceAsMap = typeMapTuple.v2(); sourceAsMap = XContentMapValues.filter(sourceAsMap, fetchSourceContext.includes(), fetchSourceContext.excludes()); try { - source = BytesReferenceUtil.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); + source = BytesReference.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); } catch (IOException e) { throw new OpenSearchException("Failed to get id [" + id + "] with includes/excludes set", e); } @@ -407,7 +406,7 @@ private GetResult innerGetLoadFromStoredFields( sourceAsMap = typeMapTuple.v2(); sourceAsMap = XContentMapValues.filter(sourceAsMap, fetchSourceContext.includes(), fetchSourceContext.excludes()); try { - source = BytesReferenceUtil.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); + source = BytesReference.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); } catch (IOException e) { throw new OpenSearchException("Failed to get id [" + id + "] with includes/excludes set", e); } diff --git a/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java index 26831378b172e..cc5cae168e7b6 100644 --- a/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java @@ -49,7 +49,6 @@ import org.opensearch.action.termvectors.TermVectorsResponse; import org.opensearch.client.Client; import org.opensearch.common.Nullable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.Strings; @@ -221,7 +220,7 @@ public Item(@Nullable String index, XContentBuilder doc) { throw new IllegalArgumentException("Item requires doc to be non-null"); } this.index = index; - this.doc = BytesReferenceUtil.bytes(doc); + this.doc = BytesReference.bytes(doc); this.xContentType = XContentType.fromMediaType(doc.contentType()); } @@ -374,7 +373,7 @@ public static Item parse(XContentParser parser, Item item) throws IOException { } else if (ID.match(currentFieldName, parser.getDeprecationHandler())) { item.id = parser.text(); } else if (DOC.match(currentFieldName, parser.getDeprecationHandler())) { - item.doc = BytesReferenceUtil.bytes(jsonBuilder().copyCurrentStructure(parser)); + item.doc = BytesReference.bytes(jsonBuilder().copyCurrentStructure(parser)); item.xContentType = XContentType.JSON; } else if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) { if (token == XContentParser.Token.START_ARRAY) { diff --git a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java index bcb3d6f4b2cc7..cab2d69ff0f9f 100644 --- a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionBuilder.java @@ -48,7 +48,6 @@ import org.opensearch.common.lucene.search.function.ScoreFunction; import org.opensearch.common.unit.DistanceUnit; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -147,7 +146,7 @@ protected DecayFunctionBuilder( } builder.field(DECAY, decay); builder.endObject(); - this.functionBytes = BytesReferenceUtil.bytes(builder); + this.functionBytes = BytesReference.bytes(builder); } catch (IOException e) { throw new IllegalArgumentException("unable to build inner function object", e); } diff --git a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java index af39bea62019e..ea27625844337 100644 --- a/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java +++ b/server/src/main/java/org/opensearch/index/query/functionscore/DecayFunctionParser.java @@ -32,7 +32,6 @@ package org.opensearch.index.query.functionscore; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesReference; @@ -125,7 +124,7 @@ public DFB fromXContent(XContentParser parser) throws IOException, ParsingExcept fieldName = currentFieldName; XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); - functionBytes = BytesReferenceUtil.bytes(builder); + functionBytes = BytesReference.bytes(builder); } else if (MULTI_VALUE_MODE.match(currentFieldName, parser.getDeprecationHandler())) { multiValueMode = MultiValueMode.fromString(parser.text()); } else { diff --git a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java index e8b56dbbdd678..90f7796bf1fdc 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java +++ b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java @@ -36,7 +36,7 @@ import org.opensearch.action.CompositeIndicesRequest; import org.opensearch.action.index.IndexRequest; import org.opensearch.action.search.SearchRequest; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -359,7 +359,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType()); builder.map(source); try ( - InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); + InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser innerParser = parser.contentType() .xContent() .createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), stream) diff --git a/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java b/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java index d67b5ec03c060..d5d69d5a6d3f8 100644 --- a/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java +++ b/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java @@ -38,7 +38,6 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -271,14 +270,14 @@ static BytesReference queryForRemote(Map source) throws IOExcept XContentBuilder builder = XContentBuilder.builder(QUERY_CONTENT_TYPE).prettyPrint(); Object query = source.remove("query"); if (query == null) { - return BytesReferenceUtil.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); + return BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); } if (!(query instanceof Map)) { throw new IllegalArgumentException("Expected [query] to be an object but was [" + query + "]"); } @SuppressWarnings("unchecked") Map map = (Map) query; - return BytesReferenceUtil.bytes(builder.map(map)); + return BytesReference.bytes(builder.map(map)); } private static boolean isQueryJson(BytesReference bytesReference) { diff --git a/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java b/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java index 622f1428953a5..dc41d1985fe42 100644 --- a/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java +++ b/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java @@ -37,7 +37,7 @@ import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchParseException; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -575,7 +575,7 @@ private static Script extractConditional(Map config) throws IOEx if (scriptSource != null) { try ( XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(normalizeScript(scriptSource)); - InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); + InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) ) { diff --git a/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java b/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java index 77048d500926c..07d0c31fc6703 100644 --- a/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java +++ b/server/src/main/java/org/opensearch/ingest/PipelineConfiguration.java @@ -34,7 +34,6 @@ import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; @@ -65,7 +64,7 @@ public final class PipelineConfiguration extends AbstractDiffable { XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent()); contentBuilder.generator().copyCurrentStructure(parser); - builder.setConfig(BytesReferenceUtil.bytes(contentBuilder), contentBuilder.contentType()); + builder.setConfig(BytesReference.bytes(contentBuilder), contentBuilder.contentType()); }, new ParseField("config"), ObjectParser.ValueType.OBJECT); } diff --git a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java index 40e23bc625433..c0d6f49a5ce0d 100644 --- a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java @@ -92,7 +92,6 @@ import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.AbstractRunnable; import org.opensearch.common.util.concurrent.ConcurrentCollections; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -1668,7 +1667,7 @@ private void doGetRepositoryData(ActionListener listener) { // since we're only caching the information that we just wrote and thus won't accidentally cache any information that // isn't safe cacheRepositoryData( - BytesReferenceUtil.bytes(loaded.snapshotsToXContent(XContentFactory.jsonBuilder(), Version.CURRENT)), + BytesReference.bytes(loaded.snapshotsToXContent(XContentFactory.jsonBuilder(), Version.CURRENT)), genToLoad ); } @@ -2051,7 +2050,7 @@ public void onFailure(Exception e) { } final String indexBlob = INDEX_FILE_PREFIX + Long.toString(newGen); logger.debug("Repository [{}] writing new index generational blob [{}]", metadata.name(), indexBlob); - final BytesReference serializedRepoData = BytesReferenceUtil.bytes( + final BytesReference serializedRepoData = BytesReference.bytes( newRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(), version) ); writeAtomic(blobContainer(), indexBlob, serializedRepoData, true); diff --git a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java index c1fa6715a64b6..4533b2ca9d703 100644 --- a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java +++ b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java @@ -41,7 +41,6 @@ import org.opensearch.OpenSearchStatusException; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -72,7 +71,7 @@ public class BytesRestResponse extends RestResponse { * Creates a new response based on {@link XContentBuilder}. */ public BytesRestResponse(RestStatus status, XContentBuilder builder) { - this(status, builder.contentType().mediaType(), BytesReferenceUtil.bytes(builder)); + this(status, builder.contentType().mediaType(), BytesReference.bytes(builder)); } /** @@ -130,7 +129,7 @@ public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) th this.status = status; try (XContentBuilder builder = channel.newErrorBuilder()) { build(builder, params, status, channel.detailedErrorsEnabled(), e); - this.content = BytesReferenceUtil.bytes(builder); + this.content = BytesReference.bytes(builder); this.contentType = builder.contentType().mediaType(); } if (e instanceof OpenSearchException) { diff --git a/server/src/main/java/org/opensearch/rest/RestRequestFilter.java b/server/src/main/java/org/opensearch/rest/RestRequestFilter.java index 5d7d320dedd78..f24c5a15c4304 100644 --- a/server/src/main/java/org/opensearch/rest/RestRequestFilter.java +++ b/server/src/main/java/org/opensearch/rest/RestRequestFilter.java @@ -35,7 +35,6 @@ import org.opensearch.OpenSearchException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.support.XContentMapValues; @@ -81,7 +80,7 @@ public BytesReference content() { ); try { XContentBuilder xContentBuilder = XContentBuilder.builder(result.v1().xContent()).map(transformedSource); - filteredBytes = BytesReferenceUtil.bytes(xContentBuilder); + filteredBytes = BytesReference.bytes(xContentBuilder); } catch (IOException e) { throw new OpenSearchException("failed to parse request", e); } diff --git a/server/src/main/java/org/opensearch/script/Script.java b/server/src/main/java/org/opensearch/script/Script.java index 15d825d9e27e3..7f6c41575ccb8 100644 --- a/server/src/main/java/org/opensearch/script/Script.java +++ b/server/src/main/java/org/opensearch/script/Script.java @@ -33,7 +33,7 @@ package org.opensearch.script; import org.opensearch.OpenSearchParseException; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; @@ -329,7 +329,7 @@ public static Script parse(Settings settings) { settings.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); try ( - InputStream stream = BytesReferenceUtil.bytes(builder).streamInput(); + InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser parser = JsonXContent.jsonXContent.createParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, diff --git a/server/src/main/java/org/opensearch/search/SearchHit.java b/server/src/main/java/org/opensearch/search/SearchHit.java index e0d0493339caf..3ad13c7e8b63d 100644 --- a/server/src/main/java/org/opensearch/search/SearchHit.java +++ b/server/src/main/java/org/opensearch/search/SearchHit.java @@ -46,7 +46,6 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.text.Text; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.ParseField; @@ -867,7 +866,7 @@ private static BytesReference parseSourceBytes(XContentParser parser) throws IOE // pretty printing are not preserved, // it all depends on the current builder settings builder.copyCurrentStructure(parser); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } diff --git a/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java b/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java index 5deee600cfca5..5a42d47662d4c 100644 --- a/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java +++ b/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourcePhase.java @@ -34,8 +34,8 @@ import org.apache.lucene.index.LeafReaderContext; import org.opensearch.OpenSearchException; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.search.SearchHit; import org.opensearch.search.fetch.FetchContext; @@ -117,7 +117,7 @@ private void hitExecute(String index, FetchSourceContext fetchSourceContext, Hit builder.startObject(); builder.endObject(); } - hitContext.hit().sourceRef(BytesReferenceUtil.bytes(builder)); + hitContext.hit().sourceRef(BytesReference.bytes(builder)); } catch (IOException e) { throw new OpenSearchException("Error filtering source", e); } diff --git a/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java b/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java index bd38dd2618c81..e2599fd78908c 100644 --- a/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java +++ b/server/src/main/java/org/opensearch/search/pipeline/PipelineConfiguration.java @@ -14,7 +14,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.ParseField; @@ -44,7 +43,7 @@ public class PipelineConfiguration extends AbstractDiffable { XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent()); contentBuilder.generator().copyCurrentStructure(parser); - builder.setConfig(BytesReferenceUtil.bytes(contentBuilder), contentBuilder.contentType()); + builder.setConfig(BytesReference.bytes(contentBuilder), contentBuilder.contentType()); }, new ParseField("config"), ObjectParser.ValueType.OBJECT); } diff --git a/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java b/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java index 2f3c7ccef689b..314adf6b8e40c 100644 --- a/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java +++ b/server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggestionBuilder.java @@ -32,7 +32,6 @@ package org.opensearch.search.suggest.completion; import org.opensearch.OpenSearchParseException; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -114,7 +113,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder keys = new ArrayList<>(parser.mapOrdered().keySet()); @@ -802,7 +801,7 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException { }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); try (XContentParser parser = createParser(xContent, failureBytes)) { - failureBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); + failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); } OpenSearchException parsedFailure; @@ -956,7 +955,7 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); try (XContentParser parser = createParser(xContent, failureBytes)) { - failureBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); + failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); } OpenSearchException parsedFailure; diff --git a/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java b/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java index dc1af8ba7f6e3..d867881c76c20 100644 --- a/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java +++ b/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java @@ -34,7 +34,7 @@ import org.opensearch.action.DocWriteResponse.Result; import org.opensearch.action.support.replication.ReplicationResponse.ShardInfo; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -112,14 +112,14 @@ public void testToXContentDoesntIncludeForcedRefreshUnlessForced() throws IOExce response.setForcedRefresh(false); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { assertThat(parser.map(), not(hasKey("forced_refresh"))); } } response.setForcedRefresh(true); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { assertThat(parser.map(), hasEntry("forced_refresh", true)); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index 34ab2f2126f87..c071b1622dd60 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -51,11 +51,11 @@ import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -772,6 +772,6 @@ private Map serialize(ListTasksResponse response, boolean byPare builder.endObject(); builder.flush(); logger.info(Strings.toString(builder)); - return XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + return XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java index d0f98b6e2f4be..284e6f538adb9 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequestTests.java @@ -8,8 +8,8 @@ package org.opensearch.action.admin.cluster.remotestore.restore; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -70,7 +70,7 @@ public void testSource() throws IOException { RestoreRemoteStoreRequest original = createTestInstance(); XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new ToXContent.MapParams(Collections.emptyMap())); XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, BytesReferenceUtil.bytes(builder).streamInput()); + .createParser(NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput()); Map map = parser.mapOrdered(); RestoreRemoteStoreRequest processed = new RestoreRemoteStoreRequest(); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java index 6ec083370a658..7d8e1ad5c7016 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsResponseTests.java @@ -9,7 +9,7 @@ package org.opensearch.action.admin.cluster.remotestore.stats; import org.opensearch.action.support.DefaultShardOperationFailedException; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.XContentBuilder; @@ -56,11 +56,8 @@ public void testSerialization() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder(); statsResponse.toXContent(builder, EMPTY_PARAMS); - Map jsonResponseObject = XContentHelper.convertToMap( - BytesReferenceUtil.bytes(builder), - false, - builder.contentType() - ).v2(); + Map jsonResponseObject = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()) + .v2(); ArrayList> statsObjectArray = (ArrayList>) jsonResponseObject.get("stats"); assertEquals(statsObjectArray.size(), 1); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java index a3228b1627492..94d2eae31c040 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/remotestore/stats/RemoteStoreStatsTests.java @@ -8,9 +8,9 @@ package org.opensearch.action.admin.cluster.remotestore.stats; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.XContentBuilder; @@ -50,7 +50,7 @@ public void testXContentBuilder() throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); stats.toXContent(builder, EMPTY_PARAMS); - Map jsonObject = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + Map jsonObject = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); compareStatsResponse(jsonObject, pressureTrackerStats); } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java index 6d9d9f1d2f07b..203bfd0db284a 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/repositories/put/PutRepositoryRequestTests.java @@ -31,8 +31,8 @@ package org.opensearch.action.admin.cluster.repositories.put; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -71,7 +71,7 @@ public void testCreateRepositoryToXContent() throws IOException { request.toXContent(builder, new ToXContent.MapParams(mapParams)); builder.flush(); - Map outputMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + Map outputMap = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); assertThat(outputMap.get("name"), equalTo(request.name())); assertThat(outputMap.get("verify"), equalTo(request.verify())); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java index 9ae8a55baaa93..b057b583caeb8 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java @@ -40,12 +40,12 @@ import org.opensearch.cluster.routing.allocation.command.AllocationCommand; import org.opensearch.cluster.routing.allocation.command.CancelAllocationCommand; import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.network.NetworkModule; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -244,7 +244,7 @@ private RestRequest toRestRequest(ClusterRerouteRequest original) throws IOExcep FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry()); requestBuilder.withParams(params); if (hasBody) { - requestBuilder.withContent(BytesReferenceUtil.bytes(builder), XContentType.fromMediaType(builder.contentType())); + requestBuilder.withContent(BytesReference.bytes(builder), XContentType.fromMediaType(builder.contentType())); } return requestBuilder.build(); } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java index 70cc8039df784..fad5155d0fd61 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestTests.java @@ -33,7 +33,6 @@ package org.opensearch.action.admin.cluster.settings; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParseException; import org.opensearch.core.xcontent.XContentParser; @@ -65,7 +64,7 @@ private void doFromXContentTestWithRandomFields(boolean addRandomFields) throws if (addRandomFields) { String unsupportedField = "unsupported_field"; - BytesReference mutated = BytesReferenceUtil.bytes( + BytesReference mutated = BytesReference.bytes( XContentTestUtils.insertIntoXContent( xContentType.xContent(), originalBytes, diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java index 6fac686e3239a..6083e74190e1b 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestTests.java @@ -36,8 +36,8 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.action.support.IndicesOptions.Option; import org.opensearch.action.support.IndicesOptions.WildcardStates; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent.MapParams; import org.opensearch.core.xcontent.XContentBuilder; @@ -125,7 +125,7 @@ public void testToXContent() throws IOException { XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new MapParams(Collections.emptyMap())); XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, BytesReferenceUtil.bytes(builder).streamInput()); + .createParser(NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput()); Map map = parser.mapOrdered(); CreateSnapshotRequest processed = new CreateSnapshotRequest((String) map.get("repository"), (String) map.get("snapshot")); processed.waitForCompletion(original.waitForCompletion()); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java index 8c4f35edde009..737e7b2e4887b 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestTests.java @@ -33,8 +33,8 @@ package org.opensearch.action.admin.cluster.snapshots.restore; import org.opensearch.action.support.IndicesOptions; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -138,7 +138,7 @@ public void testSource() throws IOException { original.snapshotUuid(null); // cannot be set via the REST API XContentBuilder builder = original.toXContent(XContentFactory.jsonBuilder(), new ToXContent.MapParams(Collections.emptyMap())); XContentParser parser = XContentType.JSON.xContent() - .createParser(NamedXContentRegistry.EMPTY, null, BytesReferenceUtil.bytes(builder).streamInput()); + .createParser(NamedXContentRegistry.EMPTY, null, BytesReference.bytes(builder).streamInput()); Map map = parser.mapOrdered(); // we will only restore properties from the map that are contained in the request body. All other diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java index 20c11f3f5c490..de5cad93980eb 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/storedscripts/PutStoredScriptRequestTests.java @@ -36,7 +36,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; @@ -77,7 +76,7 @@ public void testToXContent() throws IOException { builder.startObject("script").field("lang", "painless").field("source", "Math.log(_score * 2) + params.multiplier").endObject(); builder.endObject(); - BytesReference expectedRequestBody = BytesReferenceUtil.bytes(builder); + BytesReference expectedRequestBody = BytesReference.bytes(builder); PutStoredScriptRequest request = new PutStoredScriptRequest(); request.id("test1"); @@ -88,7 +87,7 @@ public void testToXContent() throws IOException { request.toXContent(requestBuilder, ToXContent.EMPTY_PARAMS); requestBuilder.endObject(); - BytesReference actualRequestBody = BytesReferenceUtil.bytes(requestBuilder); + BytesReference actualRequestBody = BytesReference.bytes(requestBuilder); assertEquals(expectedRequestBody, actualRequestBody); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java index e6205fe692bd7..00545898ad3e4 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/analyze/AnalyzeResponseTests.java @@ -33,8 +33,8 @@ package org.opensearch.action.admin.indices.analyze; import org.opensearch.action.admin.indices.analyze.AnalyzeAction.AnalyzeToken; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable.Reader; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -68,8 +68,7 @@ public void testNullResponseToXContent() throws IOException { AnalyzeAction.Response response = new AnalyzeAction.Response(null, detail); try (XContentBuilder builder = JsonXContent.contentBuilder()) { response.toXContent(builder, ToXContent.EMPTY_PARAMS); - Map converted = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()) - .v2(); + Map converted = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); List> tokenfiltersValue = (List>) ((Map) converted.get("detail")).get( "tokenfilters" ); diff --git a/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java index 345a9bbfe3795..176c3163697c1 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java @@ -43,7 +43,6 @@ import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -188,7 +187,7 @@ public void testUnknownFields() throws IOException { builder.endObject(); } builder.endObject(); - BytesReference mutated = XContentTestUtils.insertRandomFields(xContentType, BytesReferenceUtil.bytes(builder), null, random()); + BytesReference mutated = XContentTestUtils.insertRandomFields(xContentType, BytesReference.bytes(builder), null, random()); expectThrows(XContentParseException.class, () -> request.fromXContent(createParser(xContentType.xContent(), mutated))); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java index ce33873a746cc..2d353340aa5b0 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java @@ -38,7 +38,6 @@ import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -103,7 +102,7 @@ public void testBasicSerialization() throws Exception { contentBuilder.startObject(); storesResponse.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - BytesReference bytes = BytesReferenceUtil.bytes(contentBuilder); + BytesReference bytes = BytesReference.bytes(contentBuilder); try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) { Map map = parser.map(); diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java index 467d825dc0ca5..f71d57f68a406 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java @@ -43,7 +43,6 @@ import org.opensearch.action.update.UpdateResponseTests; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -117,7 +116,7 @@ public void testFailureToAndFromXContent() throws IOException { // Shuffle the XContent fields if (randomBoolean()) { try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - originalBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); + originalBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); } } diff --git a/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java b/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java index d2db358a66b47..cada565748de8 100644 --- a/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java +++ b/server/src/test/java/org/opensearch/action/explain/ExplainResponseTests.java @@ -34,9 +34,9 @@ import org.apache.lucene.search.Explanation; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.document.DocumentField; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -117,7 +117,7 @@ public void testToXContent() throws IOException { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); response.toXContent(builder, ToXContent.EMPTY_PARAMS); - String generatedResponse = BytesReferenceUtil.bytes(builder).utf8ToString().replaceAll("\\s+", ""); + String generatedResponse = BytesReference.bytes(builder).utf8ToString().replaceAll("\\s+", ""); String expectedResponse = ("{\n" + " \"_index\":\"index\",\n" diff --git a/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java b/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java index 664f4a64b596e..253252d76bbc9 100644 --- a/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java +++ b/server/src/test/java/org/opensearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java @@ -32,8 +32,8 @@ package org.opensearch.action.fieldcaps; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -128,7 +128,7 @@ public void testToXContent() throws IOException { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); response.toXContent(builder, ToXContent.EMPTY_PARAMS); - String generatedResponse = BytesReferenceUtil.bytes(builder).utf8ToString(); + String generatedResponse = BytesReference.bytes(builder).utf8ToString(); assertEquals( ("{" + " \"indices\": null," diff --git a/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java b/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java index 149523f0f5072..1184b05461025 100644 --- a/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java +++ b/server/src/test/java/org/opensearch/action/get/TransportMultiGetActionTests.java @@ -47,8 +47,8 @@ import org.opensearch.cluster.routing.OperationRouting; import org.opensearch.cluster.routing.ShardIterator; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.AtomicArray; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentFactory; @@ -128,7 +128,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") @@ -153,7 +153,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") diff --git a/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java b/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java index 4b085d57a9daa..68bb523d594c0 100644 --- a/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/GetPipelineResponseTests.java @@ -32,8 +32,8 @@ package org.opensearch.action.ingest; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -68,7 +68,7 @@ private PipelineConfiguration createRandomPipeline(String pipelineId) throws IOE builder.field("value", value); builder.endObject(); builder.endObject(); - return new PipelineConfiguration(pipelineId, BytesReferenceUtil.bytes(builder), builder.contentType()); + return new PipelineConfiguration(pipelineId, BytesReference.bytes(builder), builder.contentType()); } private Map createPipelineConfigMap() throws IOException { @@ -88,7 +88,7 @@ public void testXContentDeserialization() throws IOException { XContentParser parser = builder.generator() .contentType() .xContent() - .createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReferenceUtil.bytes(builder).streamInput()); + .createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(builder).streamInput()); GetPipelineResponse parsedResponse = GetPipelineResponse.fromXContent(parser); List actualPipelines = response.pipelines(); List parsedPipelines = parsedResponse.pipelines(); diff --git a/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java b/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java index a84e065df9578..8a9eda29a1d7f 100644 --- a/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/PutPipelineRequestTests.java @@ -36,7 +36,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; @@ -76,9 +75,9 @@ public void testToXContent() throws IOException { // End first processor pipelineBuilder.endArray(); pipelineBuilder.endObject(); - PutPipelineRequest request = new PutPipelineRequest("1", BytesReferenceUtil.bytes(pipelineBuilder), xContentType); + PutPipelineRequest request = new PutPipelineRequest("1", BytesReference.bytes(pipelineBuilder), xContentType); XContentBuilder requestBuilder = XContentBuilder.builder(xContentType.xContent()); - BytesReference actualRequestBody = BytesReferenceUtil.bytes(request.toXContent(requestBuilder, ToXContent.EMPTY_PARAMS)); - assertEquals(BytesReferenceUtil.bytes(pipelineBuilder), actualRequestBody); + BytesReference actualRequestBody = BytesReference.bytes(request.toXContent(requestBuilder, ToXContent.EMPTY_PARAMS)); + assertEquals(BytesReference.bytes(pipelineBuilder), actualRequestBody); } } diff --git a/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java b/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java index a95e21e7a85aa..da3f9687ae5cf 100644 --- a/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/WriteableIngestDocumentTests.java @@ -35,7 +35,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -153,8 +152,7 @@ public void testToXContent() throws IOException { builder.startObject(); writeableIngestDocument.toXContent(builder, EMPTY_PARAMS); builder.endObject(); - Map toXContentMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()) - .v2(); + Map toXContentMap = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); Map toXContentDoc = (Map) toXContentMap.get("doc"); Map toXContentSource = (Map) toXContentDoc.get("_source"); diff --git a/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java b/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java index 08e82a71986f6..5795d182e622e 100644 --- a/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java +++ b/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java @@ -36,7 +36,7 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.common.CheckedBiConsumer; import org.opensearch.common.CheckedRunnable; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; @@ -546,7 +546,7 @@ private void assertExpandWildcardsValue(IndicesOptions options, String expectedV MultiSearchRequest.writeSearchRequestParams(request, builder); Map map = XContentHelper.convertToMap( XContentType.JSON.xContent(), - BytesReferenceUtil.bytes(builder).streamInput(), + BytesReference.bytes(builder).streamInput(), false ); final String value = (String) map.get("expand_wildcards"); diff --git a/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java b/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java index 49d6a49a3dff5..ee96ce5ad505c 100644 --- a/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java @@ -40,9 +40,9 @@ import org.opensearch.OpenSearchException; import org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -143,7 +143,7 @@ public void testFromXContent() throws IOException { .endObject(); builder = shuffleXContent(builder); DefaultShardOperationFailedException parsed; - try (XContentParser parser = createParser(xContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xContent, BytesReference.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); parsed = DefaultShardOperationFailedException.fromXContent(parser); assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); diff --git a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java index 6f00b4ef2cc57..37084fada85ae 100644 --- a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java +++ b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java @@ -38,7 +38,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent.MapParams; import org.opensearch.core.xcontent.XContentBuilder; @@ -429,7 +428,7 @@ public void testFromXContentWithWildcardSpecialValues() throws IOException { builder.field("ignore_unavailable", ignoreUnavailable); builder.field("allow_no_indices", allowNoIndices); builder.endObject(); - xContentBytes = BytesReferenceUtil.bytes(builder); + xContentBytes = BytesReference.bytes(builder); } IndicesOptions fromXContentOptions; @@ -448,7 +447,7 @@ public void testFromXContentWithWildcardSpecialValues() throws IOException { builder.field("ignore_unavailable", ignoreUnavailable); builder.field("allow_no_indices", allowNoIndices); builder.endObject(); - xContentBytes = BytesReferenceUtil.bytes(builder); + xContentBytes = BytesReference.bytes(builder); } try (XContentParser parser = type.xContent().createParser(NamedXContentRegistry.EMPTY, null, xContentBytes.streamInput())) { @@ -466,7 +465,7 @@ private BytesReference toXContentBytes(IndicesOptions indicesOptions, XContentTy builder.startObject(); indicesOptions.toXContent(builder, new MapParams(Collections.emptyMap())); builder.endObject(); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } } diff --git a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java index 4aa3542f3ac6b..7f5a1925043dc 100644 --- a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java +++ b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java @@ -39,7 +39,6 @@ import org.opensearch.common.breaker.CircuitBreakingException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -113,7 +112,7 @@ public void testShardInfoToAndFromXContent() throws IOException { // Shuffle the XContent fields if (randomBoolean()) { try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - originalBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); + originalBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); } } diff --git a/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java b/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java index 5a093ac5969ba..b62050a1b8050 100644 --- a/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java +++ b/server/src/test/java/org/opensearch/action/termvectors/TransportMultiTermVectorsActionTests.java @@ -48,8 +48,8 @@ import org.opensearch.cluster.routing.OperationRouting; import org.opensearch.cluster.routing.ShardIterator; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.AtomicArray; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentFactory; @@ -129,7 +129,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") @@ -154,7 +154,7 @@ public TaskManager getTaskManager() { ) .putMapping( XContentHelper.convertToJson( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") diff --git a/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java b/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java index face747be9412..d94ca9f1e3068 100644 --- a/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java +++ b/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java @@ -42,7 +42,6 @@ import org.opensearch.common.document.DocumentField; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -491,7 +490,7 @@ public void testToAndFromXContent() throws IOException { if (randomBoolean()) { try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - originalBytes = BytesReferenceUtil.bytes(shuffleXContent(parser, randomBoolean())); + originalBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); } } diff --git a/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java b/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java index 335f27f37aabc..97865d3845c2c 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/CoordinationMetadataTests.java @@ -33,8 +33,8 @@ import org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion; import org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -134,7 +134,7 @@ public void testVotingTombstoneXContent() throws IOException { final XContentBuilder builder = JsonXContent.contentBuilder(); originalTombstone.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { final VotingConfigExclusion fromXContentTombstone = VotingConfigExclusion.fromXContent(parser); assertThat(originalTombstone, equalTo(fromXContentTombstone)); } @@ -226,7 +226,7 @@ public void testXContent() throws IOException { originalMeta.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { final CoordinationMetadata fromXContentMeta = CoordinationMetadata.fromXContent(parser); assertThat(originalMeta, equalTo(fromXContentMeta)); } diff --git a/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java b/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java index 9c9a92fc746af..853ead71b30fb 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/OpenSearchNodeCommandTests.java @@ -38,7 +38,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.common.UUIDs; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -90,7 +90,7 @@ private void runLoadStateTest(boolean hasMissingCustoms, boolean preserveUnknown XContentParser parser = createParser( hasMissingCustoms ? OpenSearchNodeCommand.namedXContentRegistry : xContentRegistry(), JsonXContent.jsonXContent, - BytesReferenceUtil.bytes(builder) + BytesReference.bytes(builder) ) ) { loadedMetadata = Metadata.fromXContent(parser); diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java index 16808c97b5a95..f6253023fbdd5 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java @@ -34,9 +34,9 @@ import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentOpenSearchExtension; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.ToXContent; @@ -93,7 +93,7 @@ public void testXContent() throws IOException { ) ); } - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); parser.nextToken(); // the beginning of the parser assertThat(IndexGraveyard.fromXContent(parser), equalTo(graveyard)); } diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java index a724de869e511..38fb1a657b9e8 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java @@ -37,6 +37,7 @@ import org.opensearch.action.admin.indices.rollover.MaxSizeCondition; import org.opensearch.action.admin.indices.rollover.RolloverInfo; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; @@ -44,7 +45,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -125,7 +125,7 @@ public void testIndexMetadataSerialization() throws IOException { builder.startObject(); IndexMetadata.FORMAT.toXContent(builder, metadata); builder.endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); final IndexMetadata fromXContentMeta = IndexMetadata.fromXContent(parser); assertEquals( "expected: " diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java index f68682567c5f0..d5de57806282d 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java @@ -34,7 +34,6 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -85,7 +84,7 @@ public void testIndexTemplateMetadataXContentRoundTrip() throws Exception { builder.startObject(); IndexTemplateMetadata.Builder.toXContentWithTypes(indexTemplateMetadata, builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - templateBytesRoundTrip = BytesReferenceUtil.bytes(builder); + templateBytesRoundTrip = BytesReference.bytes(builder); } final IndexTemplateMetadata indexTemplateMetadataRoundTrip; diff --git a/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java b/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java index 60f7eae0084c7..ce8a7826e605b 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/ManifestTests.java @@ -35,7 +35,6 @@ import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -125,7 +124,7 @@ public void testXContent() throws IOException { builder.startObject(); Manifest.FORMAT.toXContent(builder, state); builder.endObject(); - BytesReference bytes = BytesReferenceUtil.bytes(builder); + BytesReference bytes = BytesReference.bytes(builder); try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) { assertThat(Manifest.fromXContent(parser), equalTo(state)); } diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java index c6422a4f3b4c7..a744c181ee341 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java @@ -46,7 +46,6 @@ import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -479,7 +478,7 @@ public void testResolveWriteIndexRouting() { } public void testUnknownFieldClusterMetadata() throws IOException { - BytesReference metadata = BytesReferenceUtil.bytes( + BytesReference metadata = BytesReference.bytes( JsonXContent.contentBuilder().startObject().startObject("meta-data").field("random", "value").endObject().endObject() ); try (XContentParser parser = createParser(JsonXContent.jsonXContent, metadata)) { @@ -491,7 +490,7 @@ public void testUnknownFieldClusterMetadata() throws IOException { } public void testUnknownFieldIndexMetadata() throws IOException { - BytesReference metadata = BytesReferenceUtil.bytes( + BytesReference metadata = BytesReference.bytes( JsonXContent.contentBuilder().startObject().startObject("index_name").field("random", "value").endObject().endObject() ); try (XContentParser parser = createParser(JsonXContent.jsonXContent, metadata)) { @@ -521,7 +520,7 @@ public void testXContentWithIndexGraveyard() throws IOException { builder.startObject(); Metadata.FORMAT.toXContent(builder, originalMeta); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { final Metadata fromXContentMeta = Metadata.fromXContent(parser); assertThat(fromXContentMeta.indexGraveyard(), equalTo(originalMeta.indexGraveyard())); } @@ -536,7 +535,7 @@ public void testXContentClusterUUID() throws IOException { builder.startObject(); Metadata.FORMAT.toXContent(builder, originalMeta); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { final Metadata fromXContentMeta = Metadata.fromXContent(parser); assertThat(fromXContentMeta.clusterUUID(), equalTo(originalMeta.clusterUUID())); assertThat(fromXContentMeta.clusterUUIDCommitted(), equalTo(originalMeta.clusterUUIDCommitted())); @@ -596,7 +595,7 @@ public void testXContentWithCoordinationMetadata() throws IOException { Metadata.FORMAT.toXContent(builder, metadata); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { final CoordinationMetadata fromXContentMeta = Metadata.fromXContent(parser).coordinationMetadata(); assertThat(fromXContentMeta, equalTo(originalMeta)); } diff --git a/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java b/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java index 09444c03f48a0..0a4ef803068eb 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/AllocationIdTests.java @@ -34,7 +34,6 @@ import org.opensearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.json.JsonXContent; @@ -166,7 +165,7 @@ public void testSerialization() throws IOException { if (randomBoolean()) { allocationId = AllocationId.newRelocation(allocationId); } - BytesReference bytes = BytesReferenceUtil.bytes(allocationId.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)); + BytesReference bytes = BytesReference.bytes(allocationId.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)); AllocationId parsedAllocationId = AllocationId.fromXContent(createParser(JsonXContent.jsonXContent, bytes)); assertEquals(allocationId, parsedAllocationId); } diff --git a/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java b/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java index ab101a7e57586..21f10aeb91542 100644 --- a/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java +++ b/server/src/test/java/org/opensearch/common/geo/GeoJsonSerializationTests.java @@ -32,8 +32,8 @@ package org.opensearch.common.geo; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -150,7 +150,7 @@ public void testToMap() throws IOException { Geometry geometry = GeometryTestUtils.randomGeometry(randomBoolean()); XContentBuilder builder = XContentFactory.jsonBuilder(); GeoJson.toXContent(geometry, builder, ToXContent.EMPTY_PARAMS); - StreamInput input = BytesReferenceUtil.bytes(builder).streamInput(); + StreamInput input = BytesReference.bytes(builder).streamInput(); try ( XContentParser parser = XContentType.JSON.xContent() diff --git a/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java b/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java index c3b04352a5619..f94fbb58311bf 100644 --- a/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java +++ b/server/src/test/java/org/opensearch/common/geo/GeoUtilTests.java @@ -32,7 +32,7 @@ package org.opensearch.common.geo; import org.opensearch.common.CheckedConsumer; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -72,7 +72,7 @@ private int parsePrecision(CheckedConsumer tokenGe XContentBuilder builder = jsonBuilder().startObject(); tokenGenerator.accept(builder); builder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); // { assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); // field name assertTrue(parser.nextToken().isValue()); // field value diff --git a/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java index ffd2743b283dc..6cfc63e5193a8 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java @@ -39,7 +39,6 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Constants; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; @@ -125,11 +124,11 @@ public void testContentType() throws IOException { } public void testStartEndObject() throws IOException { - expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startObject())); + expectUnclosedException(() -> BytesReference.bytes(builder().startObject())); expectUnclosedException(() -> builder().startObject().close()); expectUnclosedException(() -> Strings.toString(builder().startObject())); - expectObjectException(() -> BytesReferenceUtil.bytes(builder().endObject())); + expectObjectException(() -> BytesReference.bytes(builder().endObject())); expectObjectException(() -> builder().endObject().close()); expectObjectException(() -> Strings.toString(builder().endObject())); @@ -146,11 +145,11 @@ public void testStartEndObject() throws IOException { } public void testStartEndArray() throws IOException { - expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startArray())); + expectUnclosedException(() -> BytesReference.bytes(builder().startArray())); expectUnclosedException(() -> builder().startArray().close()); expectUnclosedException(() -> Strings.toString(builder().startArray())); - expectArrayException(() -> BytesReferenceUtil.bytes(builder().endArray())); + expectArrayException(() -> BytesReference.bytes(builder().endArray())); expectArrayException(() -> builder().endArray().close()); expectArrayException(() -> Strings.toString(builder().endArray())); @@ -163,17 +162,17 @@ public void testStartEndArray() throws IOException { } public void testField() throws IOException { - expectValueException(() -> BytesReferenceUtil.bytes(builder().field("foo"))); - expectNonNullFieldException(() -> BytesReferenceUtil.bytes(builder().field(null))); - expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startObject().field("foo"))); + expectValueException(() -> BytesReference.bytes(builder().field("foo"))); + expectNonNullFieldException(() -> BytesReference.bytes(builder().field(null))); + expectUnclosedException(() -> BytesReference.bytes(builder().startObject().field("foo"))); assertResult("{'foo':'bar'}", () -> builder().startObject().field("foo").value("bar").endObject()); } public void testNullField() throws IOException { - expectValueException(() -> BytesReferenceUtil.bytes(builder().nullField("foo"))); - expectNonNullFieldException(() -> BytesReferenceUtil.bytes(builder().nullField(null))); - expectUnclosedException(() -> BytesReferenceUtil.bytes(builder().startObject().nullField("foo"))); + expectValueException(() -> BytesReference.bytes(builder().nullField("foo"))); + expectNonNullFieldException(() -> BytesReference.bytes(builder().nullField(null))); + expectUnclosedException(() -> BytesReference.bytes(builder().startObject().nullField("foo"))); assertResult("{'foo':null}", () -> builder().startObject().nullField("foo").endObject()); } @@ -327,7 +326,7 @@ public void testBinaryField() throws Exception { assertResult("{'binary':null}", () -> builder().startObject().field("binary", (byte[]) null).endObject()); final byte[] randomBytes = randomBytes(); - BytesReference bytes = BytesReferenceUtil.bytes(builder().startObject().field("binary", randomBytes).endObject()); + BytesReference bytes = BytesReference.bytes(builder().startObject().field("binary", randomBytes).endObject()); try (XContentParser parser = createParser(xcontentType().xContent(), bytes)) { assertSame(parser.nextToken(), Token.START_OBJECT); @@ -344,7 +343,7 @@ public void testBinaryValue() throws Exception { assertResult("{'binary':null}", () -> builder().startObject().field("binary").value((byte[]) null).endObject()); final byte[] randomBytes = randomBytes(); - BytesReference bytes = BytesReferenceUtil.bytes(builder().startObject().field("binary").value(randomBytes).endObject()); + BytesReference bytes = BytesReference.bytes(builder().startObject().field("binary").value(randomBytes).endObject()); try (XContentParser parser = createParser(xcontentType().xContent(), bytes)) { assertSame(parser.nextToken(), Token.START_OBJECT); @@ -372,7 +371,7 @@ public void testBinaryValueWithOffsetLength() throws Exception { } builder.endObject(); - try (XContentParser parser = createParser(xcontentType().xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xcontentType().xContent(), BytesReference.bytes(builder))) { assertSame(parser.nextToken(), Token.START_OBJECT); assertSame(parser.nextToken(), Token.FIELD_NAME); assertEquals(parser.currentName(), "bin"); @@ -391,7 +390,7 @@ public void testBinaryUTF8() throws Exception { builder.field("utf8").utf8Value(randomBytesRef.bytes, randomBytesRef.offset, randomBytesRef.length); builder.endObject(); - try (XContentParser parser = createParser(xcontentType().xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xcontentType().xContent(), BytesReference.bytes(builder))) { assertSame(parser.nextToken(), Token.START_OBJECT); assertSame(parser.nextToken(), Token.FIELD_NAME); assertEquals(parser.currentName(), "utf8"); @@ -410,7 +409,7 @@ public void testText() throws Exception { final BytesReference random = new BytesArray(randomBytes()); XContentBuilder builder = builder().startObject().field("text", new Text(random)).endObject(); - try (XContentParser parser = createParser(xcontentType().xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(xcontentType().xContent(), BytesReference.bytes(builder))) { assertSame(parser.nextToken(), Token.START_OBJECT); assertSame(parser.nextToken(), Token.FIELD_NAME); assertEquals(parser.currentName(), "text"); @@ -1193,7 +1192,7 @@ public void testNamedObject() throws IOException { b.value("test"); try ( XContentParser p = xcontentType().xContent() - .createParser(registry, LoggingDeprecationHandler.INSTANCE, BytesReferenceUtil.bytes(b).streamInput()) + .createParser(registry, LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(b).streamInput()) ) { assertEquals(test1, p.namedObject(Object.class, "test1", null)); assertEquals(test2, p.namedObject(Object.class, "test2", null)); @@ -1265,7 +1264,7 @@ public static Matcher equalToJson(String json) { private static void assertResult(String expected, Builder builder) throws IOException { // Build the XContentBuilder, convert its bytes to JSON and check it matches - assertThat(XContentHelper.convertToJson(BytesReferenceUtil.bytes(builder.build()), randomBoolean()), equalToJson(expected)); + assertThat(XContentHelper.convertToJson(BytesReference.bytes(builder.build()), randomBoolean()), equalToJson(expected)); } private static byte[] randomBytes() throws Exception { diff --git a/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java b/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java index bf8c19df05913..70e7a776c5c30 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/XContentFactoryTests.java @@ -37,7 +37,6 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.test.OpenSearchTestCase; @@ -80,7 +79,7 @@ private void testGuessType(XContentType type) throws IOException { sb.append(new String(chars)).append(content); bytes = new BytesArray(sb.toString()); } else { - bytes = BytesReferenceUtil.bytes(builder); + bytes = BytesReference.bytes(builder); } assertThat(XContentHelper.xContentType(bytes), equalTo(type)); diff --git a/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java b/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java index 927013df4916d..4af333355c2b4 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/builder/XContentBuilderTests.java @@ -35,10 +35,10 @@ import org.apache.lucene.util.BytesRef; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.io.PathUtils; import org.opensearch.common.io.stream.BytesStreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentOpenSearchExtension; import org.opensearch.common.xcontent.XContentFactory; @@ -191,7 +191,7 @@ public void testWritingBinaryToStream() throws Exception { public void testByteConversion() throws Exception { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.startObject().field("test_name", (Byte) (byte) 120).endObject(); - assertThat(BytesReferenceUtil.bytes(builder).utf8ToString(), equalTo("{\"test_name\":120}")); + assertThat(BytesReference.bytes(builder).utf8ToString(), equalTo("{\"test_name\":120}")); } public void testDateTypesConversion() throws Exception { @@ -235,7 +235,7 @@ public void testCopyCurrentStructure() throws Exception { XContentBuilder filterBuilder = null; XContentParser.Token token; - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { String currentFieldName = null; assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); @@ -255,7 +255,7 @@ public void testCopyCurrentStructure() throws Exception { } } assertNotNull(filterBuilder); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(filterBuilder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(filterBuilder))) { assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME)); assertThat(parser.currentName(), equalTo("terms")); diff --git a/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java b/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java index 603031256058f..4d1a93ed68d1e 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/cbor/CborXContentParserTests.java @@ -33,7 +33,6 @@ package org.opensearch.common.xcontent.cbor; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.test.OpenSearchTestCase; @@ -42,7 +41,7 @@ public class CborXContentParserTests extends OpenSearchTestCase { public void testEmptyValue() throws IOException { - BytesReference ref = BytesReferenceUtil.bytes(XContentFactory.cborBuilder().startObject().field("field", "").endObject()); + BytesReference ref = BytesReference.bytes(XContentFactory.cborBuilder().startObject().field("field", "").endObject()); for (int i = 0; i < 2; i++) { // Running this part twice triggers the issue. diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java index 8a634ebb21c6f..a82db09e37de1 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/AbstractFilteringTestCase.java @@ -34,7 +34,6 @@ import org.opensearch.common.CheckedFunction; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -1090,7 +1089,7 @@ public void testRawField() throws Exception { .endObject(); Builder sampleWithRaw = builder -> { - BytesReference raw = BytesReferenceUtil.bytes( + BytesReference raw = BytesReference.bytes( XContentBuilder.builder(builder.contentType().xContent()).startObject().field("content", "hello world!").endObject() ); return builder.startObject().field("foo", 0).rawField("raw", raw.streamInput()).endObject(); @@ -1104,7 +1103,7 @@ public void testRawField() throws Exception { testFilter(expectedRawFieldNotFiltered, sampleWithRaw, emptySet(), singleton("f*")); sampleWithRaw = builder -> { - BytesReference raw = BytesReferenceUtil.bytes( + BytesReference raw = BytesReference.bytes( XContentBuilder.builder(builder.contentType().xContent()).startObject().field("content", "hello world!").endObject() ); return builder.startObject().field("foo", 0).rawField("raw", raw.streamInput()).endObject(); diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java b/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java index 6faee499d74cf..ed4a48bec32cf 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/XContentHelperTests.java @@ -34,7 +34,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -148,7 +147,7 @@ public void testChildBytes() throws IOException { .endObject(); builder.field("field", "value"); builder.endObject().endObject(); - BytesReference input = BytesReferenceUtil.bytes(builder); + BytesReference input = BytesReference.bytes(builder); BytesReference bytes; try ( @@ -218,7 +217,7 @@ public void testEmbeddedObject() throws IOException { CompressedXContent embedded = new CompressedXContent("{\"field\":\"value\"}"); builder.field("bytes", embedded.compressed()); builder.endObject().endObject(); - BytesReference bytes = BytesReferenceUtil.bytes(builder); + BytesReference bytes = BytesReference.bytes(builder); BytesReference inner; try ( diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java b/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java index c9bd902728c40..ca7e04cd70584 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/XContentMapValuesTests.java @@ -33,8 +33,8 @@ package org.opensearch.common.xcontent.support; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -423,11 +423,7 @@ public void testFilterWithEmptyIncludesExcludes() { public void testThatFilterIncludesEmptyObjectWhenUsingIncludes() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("obj").endObject().endObject(); - Tuple> mapTuple = convertToMap( - BytesReferenceUtil.bytes(builder), - true, - builder.contentType() - ); + Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[] { "obj" }, Strings.EMPTY_ARRAY); assertThat(mapTuple.v2(), equalTo(filteredSource)); @@ -436,11 +432,7 @@ public void testThatFilterIncludesEmptyObjectWhenUsingIncludes() throws Exceptio public void testThatFilterIncludesEmptyObjectWhenUsingExcludes() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("obj").endObject().endObject(); - Tuple> mapTuple = convertToMap( - BytesReferenceUtil.bytes(builder), - true, - builder.contentType() - ); + Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); Map filteredSource = XContentMapValues.filter( mapTuple.v2(), Strings.EMPTY_ARRAY, @@ -454,11 +446,7 @@ public void testThatFilterIncludesEmptyObjectWhenUsingExcludes() throws Exceptio public void testNotOmittingObjectsWithExcludedProperties() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("obj").field("f1", "v1").endObject().endObject(); - Tuple> mapTuple = convertToMap( - BytesReferenceUtil.bytes(builder), - true, - builder.contentType() - ); + Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[] { "obj.f1" }); assertThat(filteredSource.size(), equalTo(1)); @@ -479,11 +467,7 @@ public void testNotOmittingObjectWithNestedExcludedObject() throws Exception { .endObject(); // implicit include - Tuple> mapTuple = convertToMap( - BytesReferenceUtil.bytes(builder), - true, - builder.contentType() - ); + Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), Strings.EMPTY_ARRAY, new String[] { "*.obj2" }); assertThat(filteredSource.size(), equalTo(1)); @@ -514,11 +498,7 @@ public void testIncludingObjectWithNestedIncludedObject() throws Exception { .endObject() .endObject(); - Tuple> mapTuple = convertToMap( - BytesReferenceUtil.bytes(builder), - true, - builder.contentType() - ); + Tuple> mapTuple = convertToMap(BytesReference.bytes(builder), true, builder.contentType()); Map filteredSource = XContentMapValues.filter(mapTuple.v2(), new String[] { "*.obj2" }, Strings.EMPTY_ARRAY); assertThat(filteredSource.size(), equalTo(1)); diff --git a/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java index d5e15a6721de4..ddebc67a08ae3 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/support/filtering/AbstractXContentFilteringTestCase.java @@ -34,7 +34,7 @@ import org.junit.Assert; import org.opensearch.common.Strings; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContent; @@ -94,12 +94,12 @@ static void assertXContentBuilderAsBytes(final XContentBuilder expected, final X XContentParser jsonParser = xContent.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(expected).streamInput() + BytesReference.bytes(expected).streamInput() ); XContentParser testParser = xContent.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(actual).streamInput() + BytesReference.bytes(actual).streamInput() ); ) { while (true) { diff --git a/server/src/test/java/org/opensearch/index/IndexTests.java b/server/src/test/java/org/opensearch/index/IndexTests.java index 7e35d297ed99f..0efe25ca3cbcb 100644 --- a/server/src/test/java/org/opensearch/index/IndexTests.java +++ b/server/src/test/java/org/opensearch/index/IndexTests.java @@ -34,7 +34,7 @@ import org.opensearch.cluster.ClusterState; import org.opensearch.common.UUIDs; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -71,7 +71,7 @@ public void testXContent() throws IOException { final Index original = new Index(name, uuid); final XContentBuilder builder = JsonXContent.contentBuilder(); original.toXContent(builder, ToXContent.EMPTY_PARAMS); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { parser.nextToken(); // the beginning of the parser assertThat(Index.fromXContent(parser), equalTo(original)); } diff --git a/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java b/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java index e7062df63e6a5..75a346e444b73 100644 --- a/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java +++ b/server/src/test/java/org/opensearch/index/IndexingSlowLogTests.java @@ -47,7 +47,6 @@ import org.opensearch.common.logging.MockAppender; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexingSlowLog.IndexingSlowLogMessage; @@ -219,7 +218,7 @@ private IndexMetadata createIndexMetadata(SlowLogLevel level, String index, Stri } public void testSlowLogMessageHasJsonFields() throws IOException { - BytesReference source = BytesReferenceUtil.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); + BytesReference source = BytesReference.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); ParsedDocument pd = new ParsedDocument( new NumericDocValuesField("version", 1), SeqNoFieldMapper.SequenceIDFields.emptySeqID(), @@ -247,7 +246,7 @@ public void testSlowLogMessageHasJsonFields() throws IOException { } public void testSlowLogParsedDocumentPrinterSourceToLog() throws IOException { - BytesReference source = BytesReferenceUtil.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); + BytesReference source = BytesReference.bytes(JsonXContent.contentBuilder().startObject().field("foo", "bar").endObject()); ParsedDocument pd = new ParsedDocument( new NumericDocValuesField("version", 1), SeqNoFieldMapper.SequenceIDFields.emptySeqID(), diff --git a/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java b/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java index fd9973088acd9..fef7b67da5c34 100644 --- a/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java +++ b/server/src/test/java/org/opensearch/index/fielddata/BinaryDVFieldDataTests.java @@ -35,8 +35,8 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.BytesRef; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -81,16 +81,16 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(doc), XContentType.JSON)); + ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); BytesRef bytes1 = randomBytes(); doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1.bytes, bytes1.offset, bytes1.length).endObject(); - d = mapper.parse(new SourceToParse("test", "2", BytesReferenceUtil.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "2", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); doc = XContentFactory.jsonBuilder().startObject().endObject(); - d = mapper.parse(new SourceToParse("test", "3", BytesReferenceUtil.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "3", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); // test remove duplicate value @@ -106,7 +106,7 @@ public void testDocValue() throws Exception { doc.endArray(); } doc.endObject(); - d = mapper.parse(new SourceToParse("test", "4", BytesReferenceUtil.bytes(doc), XContentType.JSON)); + d = mapper.parse(new SourceToParse("test", "4", BytesReference.bytes(doc), XContentType.JSON)); writer.addDocument(d.rootDoc()); IndexFieldData indexFieldData = getForField("field"); diff --git a/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java index 493c95b1c6291..1f99c855ce806 100644 --- a/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java @@ -47,8 +47,8 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.Fuzziness; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.ToXContent; @@ -209,7 +209,7 @@ public void testTypeParsing() throws Exception { XContentBuilder builder = jsonBuilder().startObject(); fieldMapper.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true"))).endObject(); builder.close(); - Map serializedMap = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)).map(); + Map serializedMap = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)).map(); Map configMap = (Map) serializedMap.get("field"); assertThat(configMap.get("analyzer").toString(), is("simple")); assertThat(configMap.get("search_analyzer").toString(), is("standard")); diff --git a/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java index 2652570a3172a..5fe1a979ef1e7 100644 --- a/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/CopyToMapperTests.java @@ -33,7 +33,7 @@ package org.opensearch.index.mapper; import org.apache.lucene.index.IndexableField; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -85,7 +85,7 @@ public void testCopyToFieldsParsing() throws Exception { stringFieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject(); builder.close(); Map serializedMap; - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { serializedMap = parser.map(); } Map copyTestMap = (Map) serializedMap.get("copy_test"); diff --git a/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java index d87216b36d6f1..374b7ac9a5271 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DataStreamFieldMapperTests.java @@ -9,8 +9,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -77,7 +77,7 @@ public void testDeeplyNestedCustomTimestampField() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("event") @@ -97,7 +97,7 @@ public void testDeeplyNestedCustomTimestampField() throws Exception { new SourceToParse( "test", "3", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("event") @@ -126,7 +126,7 @@ private void assertDataStreamFieldMapper(String mapping, String timestampFieldNa new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder().startObject().field(timestampFieldName, "2020-12-06T11:04:05.000Z").endObject() ), XContentType.JSON @@ -144,7 +144,7 @@ private void assertDataStreamFieldMapper(String mapping, String timestampFieldNa new SourceToParse( "test", "2", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder().startObject().field("invalid-field-name", "2020-12-06T11:04:05.000Z").endObject() ), XContentType.JSON @@ -162,7 +162,7 @@ private void assertDataStreamFieldMapper(String mapping, String timestampFieldNa new SourceToParse( "test", "3", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .array(timestampFieldName, "2020-12-06T11:04:05.000Z", "2020-12-07T11:04:05.000Z") diff --git a/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java index a4373c45af8ea..222cdf9f7684c 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java @@ -34,7 +34,6 @@ import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -360,7 +359,7 @@ public void testDefaultFloatingPointMappings() throws IOException { } private void doTestDefaultFloatingPointMappings(DocumentMapper mapper, XContentBuilder builder) throws IOException { - BytesReference source = BytesReferenceUtil.bytes( + BytesReference source = BytesReference.bytes( builder.startObject() .field("foo", 3.2f) // float .field("bar", 3.2d) // double diff --git a/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java index da4a7b8f39af2..639de9d314641 100644 --- a/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/FieldNamesFieldMapperTests.java @@ -35,8 +35,8 @@ import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -111,7 +111,7 @@ public void testInjectIntoDocDuringParsing() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder().startObject().field("a", "100").startObject("b").field("c", 42).endObject().endObject() ), XContentType.JSON @@ -148,7 +148,7 @@ public void testExplicitEnabled() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); @@ -178,7 +178,7 @@ public void testDisabled() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java b/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java index 304d5df9ea92b..54393b10a3c5d 100644 --- a/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java @@ -9,8 +9,8 @@ import org.apache.lucene.index.LeafReaderContext; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; @@ -43,7 +43,7 @@ public void testDocValue() throws Exception { final DocumentMapper mapper = mapperService.documentMapperParser().parse("test", new CompressedXContent(mapping)); XContentBuilder json = XContentFactory.jsonBuilder().startObject().startObject("field").field("foo", "bar").endObject().endObject(); - ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(json), XContentType.JSON)); + ParsedDocument d = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(json), XContentType.JSON)); writer.addDocument(d.rootDoc()); writer.commit(); diff --git a/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java index 80ab4ec52543e..93d0596a9bfb5 100644 --- a/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/IdFieldMapperTests.java @@ -36,9 +36,9 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexService; @@ -73,7 +73,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("_id", "1").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_id", "1").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java index 07c2221c15626..c4225cb576550 100644 --- a/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/IndexFieldMapperTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; @@ -64,7 +64,7 @@ public void testDefaultDisabledIndexMapper() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java index 506c02f6bcbf7..e5c8e822b2f56 100644 --- a/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/IpRangeFieldMapperTests.java @@ -35,9 +35,9 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.network.InetAddresses; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -176,6 +176,6 @@ private final SourceToParse source(CheckedConsumer XContentBuilder builder = JsonXContent.contentBuilder().startObject(); build.accept(builder); builder.endObject(); - return new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON); + return new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON); } } diff --git a/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java b/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java index 6ada4acdec0b4..7e00a463124f1 100644 --- a/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/JavaMultiFieldMergeTests.java @@ -35,7 +35,6 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.ParseContext.Document; @@ -56,7 +55,7 @@ public void testMergeMultiField() throws Exception { assertTrue(mapperService.fieldType("name").isSearchable()); assertThat(mapperService.fieldType("name.indexed"), nullValue()); - BytesReference json = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); + BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); @@ -109,7 +108,7 @@ public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception { assertTrue(mapperService.fieldType("name").isSearchable()); assertThat(mapperService.fieldType("name.indexed"), nullValue()); - BytesReference json = BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); + BytesReference json = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("name", "some name").endObject()); Document doc = mapperService.documentMapper().parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc(); IndexableField f = doc.getField("name"); assertThat(f, notNullValue()); diff --git a/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java b/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java index c8021b7242b3f..01a901b3cd5cb 100644 --- a/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java @@ -35,9 +35,9 @@ import org.apache.lucene.analysis.TokenStream; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.env.Environment; @@ -124,7 +124,7 @@ private CompressedXContent createMappingSpecifyingNumberOfFields(int numberOfFie mappingBuilder.endObject(); } mappingBuilder.endObject().endObject(); - return new CompressedXContent(BytesReferenceUtil.bytes(mappingBuilder)); + return new CompressedXContent(BytesReference.bytes(mappingBuilder)); } public void testMappingDepthExceedsLimit() throws Throwable { @@ -136,7 +136,7 @@ public void testMappingDepthExceedsLimit() throws Throwable { indexService1.mapperService().merge("type", createMappingSpecifyingNumberOfFields(1), MergeReason.MAPPING_UPDATE); CompressedXContent objectMapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -203,7 +203,7 @@ public void testIndexSortWithNestedFields() throws IOException { assertThat(invalidNestedException.getMessage(), containsString("cannot have nested fields when index sort is activated")); IndexService indexService = createIndex("test", settings, "t", "foo", "type=keyword"); CompressedXContent nestedFieldMapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -226,7 +226,7 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable { MapperService mapperService = indexService.mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -246,7 +246,7 @@ public void testFieldAliasWithMismatchedNestedScope() throws Throwable { mapperService.merge("type", mapping, MergeReason.MAPPING_UPDATE); CompressedXContent mappingUpdate = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -311,7 +311,7 @@ public void testFieldNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -328,7 +328,7 @@ public void testFieldNameLengthLimit() throws Throwable { mapperService.merge("type", mapping, MergeReason.MAPPING_UPDATE); CompressedXContent mappingUpdate = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -356,7 +356,7 @@ public void testObjectNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -386,7 +386,7 @@ public void testAliasFieldNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -420,7 +420,7 @@ public void testMappingRecoverySkipFieldNameLengthLimit() throws Throwable { MapperService mapperService = createIndex("test1", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("type") @@ -450,7 +450,7 @@ public void testReloadSearchAnalyzers() throws IOException { MapperService mapperService = createIndex("test_index", settings).mapperService(); CompressedXContent mapping = new CompressedXContent( - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("_doc") diff --git a/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java index 7a8af30559361..7722e7c07d8a9 100644 --- a/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java @@ -34,9 +34,9 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -87,9 +87,7 @@ public void testEmptyNested() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( - XContentFactory.jsonBuilder().startObject().field("field", "value").nullField("nested1").endObject() - ), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").nullField("nested1").endObject()), XContentType.JSON ) ); @@ -100,7 +98,7 @@ public void testEmptyNested() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested").endArray().endObject() ), XContentType.JSON @@ -136,7 +134,7 @@ public void testSingleNested() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -161,7 +159,7 @@ public void testSingleNested() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -229,7 +227,7 @@ public void testMultiNested() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -323,7 +321,7 @@ public void testMultiObjectAndNested1() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -418,7 +416,7 @@ public void testMultiObjectAndNested2() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -512,7 +510,7 @@ public void testMultiRootAndNested1() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -606,7 +604,7 @@ public void testMultipleLevelsIncludeRoot1() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startArray("nested1") @@ -675,7 +673,7 @@ public void testMultipleLevelsIncludeRoot2() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startArray("nested1") @@ -759,7 +757,7 @@ public void testMultipleLevelsIncludeRootWithMerge() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startArray("nested1") @@ -814,7 +812,7 @@ public void testNestedArrayStrict() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field", "value") @@ -965,7 +963,7 @@ public void testLimitNestedDocsDefaultSettings() throws Exception { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = new SourceToParse("test1", "1", BytesReferenceUtil.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "1", BytesReference.bytes(docBuilder), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source1)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" @@ -1010,7 +1008,7 @@ public void testLimitNestedDocs() throws Exception { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = new SourceToParse("test1", "1", BytesReferenceUtil.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "1", BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -1027,7 +1025,7 @@ public void testLimitNestedDocs() throws Exception { docBuilder2.endArray(); } docBuilder2.endObject(); - SourceToParse source2 = new SourceToParse("test1", "2", BytesReferenceUtil.bytes(docBuilder2), XContentType.JSON); + SourceToParse source2 = new SourceToParse("test1", "2", BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" @@ -1079,7 +1077,7 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception { docBuilder.endArray(); } docBuilder.endObject(); - SourceToParse source1 = new SourceToParse("test1", "1", BytesReferenceUtil.bytes(docBuilder), XContentType.JSON); + SourceToParse source1 = new SourceToParse("test1", "1", BytesReference.bytes(docBuilder), XContentType.JSON); ParsedDocument doc = docMapper.parse(source1); assertThat(doc.docs().size(), equalTo(3)); @@ -1101,7 +1099,7 @@ public void testLimitNestedDocsMultipleNestedFields() throws Exception { } docBuilder2.endObject(); - SourceToParse source2 = new SourceToParse("test1", "2", BytesReferenceUtil.bytes(docBuilder2), XContentType.JSON); + SourceToParse source2 = new SourceToParse("test1", "2", BytesReference.bytes(docBuilder2), XContentType.JSON); MapperParsingException e = expectThrows(MapperParsingException.class, () -> docMapper.parse(source2)); assertEquals( "The number of nested documents has exceeded the allowed limit of [" diff --git a/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java index 1fc5e8cde1b18..95c21823bfcae 100644 --- a/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/NullValueObjectMappingTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -66,7 +66,7 @@ public void testNullValueObject() throws IOException { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder().startObject().startObject("obj1").endObject().field("value1", "test1").endObject() ), XContentType.JSON @@ -79,9 +79,7 @@ public void testNullValueObject() throws IOException { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( - XContentFactory.jsonBuilder().startObject().nullField("obj1").field("value1", "test1").endObject() - ), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("obj1").field("value1", "test1").endObject()), XContentType.JSON ) ); @@ -92,7 +90,7 @@ public void testNullValueObject() throws IOException { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("obj1") diff --git a/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java index 1cb01a241d6f3..92236ad34013b 100644 --- a/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/RoutingFieldMapperTests.java @@ -33,8 +33,8 @@ package org.opensearch.index.mapper; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -54,7 +54,7 @@ public void testRoutingMapper() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON, "routing_value" ) @@ -75,7 +75,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("_routing", "foo").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("_routing", "foo").endObject()), XContentType.JSON ) ); diff --git a/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java index f1c9525daa7c8..6925faa44b556 100644 --- a/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/SourceFieldMapperTests.java @@ -35,8 +35,8 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.xcontent.XContentParser; @@ -70,7 +70,7 @@ public void testNoFormat() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), + BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()), XContentType.JSON ) ); @@ -82,7 +82,7 @@ public void testNoFormat() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes(XContentFactory.smileBuilder().startObject().field("field", "value").endObject()), + BytesReference.bytes(XContentFactory.smileBuilder().startObject().field("field", "value").endObject()), XContentType.SMILE ) ); @@ -110,7 +110,7 @@ public void testIncludes() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("path1") @@ -154,7 +154,7 @@ public void testExcludes() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .startObject("path1") diff --git a/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java b/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java index e4e8666c6aa38..3a608ebe828e1 100644 --- a/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/StoredNumericValuesTests.java @@ -38,9 +38,9 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.ByteBuffersDirectory; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.lucene.Lucene; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -117,7 +117,7 @@ public void testBytesAndNumericRepresentation() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("field1", 1) diff --git a/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java b/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java index f385c94151e3f..5b536a5756c95 100644 --- a/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/TypeParsersTests.java @@ -33,7 +33,7 @@ package org.opensearch.index.mapper; import org.opensearch.Version; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -85,7 +85,7 @@ public void testMultiFieldWithinMultiField() throws IOException { Mapper.TypeParser typeParser = KeywordFieldMapper.PARSER; - Map fieldNode = XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), true, mapping.contentType()).v2(); + Map fieldNode = XContentHelper.convertToMap(BytesReference.bytes(mapping), true, mapping.contentType()).v2(); MapperService mapperService = mock(MapperService.class); IndexAnalyzers indexAnalyzers = new IndexAnalyzers(defaultAnalyzers(), Collections.emptyMap(), Collections.emptyMap()); diff --git a/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java index 0cb3b57201bda..cd22f72c8ffbc 100644 --- a/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java @@ -35,9 +35,9 @@ import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.index.IndexService; @@ -91,7 +91,7 @@ protected void testConflictWhileMergingAndMappingUnchanged(XContentBuilder mappi indexService.mapperService() .merge( MapperService.SINGLE_MAPPING_NAME, - new CompressedXContent(BytesReferenceUtil.bytes(mappingUpdate)), + new CompressedXContent(BytesReference.bytes(mappingUpdate)), MapperService.MergeReason.MAPPING_UPDATE ); fail(); diff --git a/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java b/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java index 6b955bc6a785a..44fb838cfc647 100644 --- a/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java +++ b/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java @@ -37,7 +37,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -90,7 +89,7 @@ protected ReindexRequest createTestInstance() { if (randomBoolean()) { try (XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint()) { - BytesReference query = BytesReferenceUtil.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); + BytesReference query = BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)); reindexRequest.setRemoteInfo( new RemoteInfo( randomAlphaOfLength(5), @@ -366,7 +365,7 @@ public void testReindexFromRemoteRequestParsing() throws IOException { b.endObject(); } b.endObject(); - request = BytesReferenceUtil.bytes(b); + request = BytesReference.bytes(b); } try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) { ReindexRequest r = ReindexRequest.fromXContent(p); @@ -423,7 +422,7 @@ private ReindexRequest parseRequestWithSourceIndices(Object sourceIndices) throw b.endObject(); } b.endObject(); - request = BytesReferenceUtil.bytes(b); + request = BytesReference.bytes(b); } try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) { return ReindexRequest.fromXContent(p); diff --git a/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java b/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java index f0058cdf5f139..16d5fb9c404b3 100644 --- a/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java +++ b/server/src/test/java/org/opensearch/index/search/geo/GeoPointParsingTests.java @@ -33,9 +33,9 @@ package org.opensearch.index.search.geo; import org.opensearch.OpenSearchParseException; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.geo.GeoUtils; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -140,12 +140,12 @@ public void testInvalidPointEmbeddedObject() throws IOException { content.endObject(); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -158,12 +158,12 @@ public void testInvalidPointLatHashMix() throws IOException { content.field("lat", 0).field("geohash", stringEncode(0d, 0d)); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -176,13 +176,13 @@ public void testInvalidPointLonHashMix() throws IOException { content.field("lon", 0).field("geohash", stringEncode(0d, 0d)); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -195,13 +195,13 @@ public void testInvalidField() throws IOException { content.field("lon", 0).field("lat", 0).field("test", 0); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); } - try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser2 = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser2.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(toObject(parser2), randomBoolean())); assertThat(e.getMessage(), is(ERR_MSG_INVALID_FIELDS)); @@ -214,7 +214,7 @@ public void testInvalidGeoHash() throws IOException { content.field("geohash", "!!!!"); content.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content))) { parser.nextToken(); Exception e = expectThrows(OpenSearchParseException.class, () -> GeoUtils.parseGeoPoint(parser)); @@ -227,7 +227,7 @@ private XContentParser objectLatLon(double lat, double lon) throws IOException { content.startObject(); content.field("lat", lat).field("lon", lon); content.endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); parser.nextToken(); return parser; } @@ -235,7 +235,7 @@ private XContentParser objectLatLon(double lat, double lon) throws IOException { private XContentParser arrayLatLon(double lat, double lon) throws IOException { XContentBuilder content = JsonXContent.contentBuilder(); content.startArray().value(lon).value(lat).endArray(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); parser.nextToken(); return parser; } @@ -243,7 +243,7 @@ private XContentParser arrayLatLon(double lat, double lon) throws IOException { private XContentParser stringLatLon(double lat, double lon) throws IOException { XContentBuilder content = JsonXContent.contentBuilder(); content.value(Double.toString(lat) + ", " + Double.toString(lon)); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); parser.nextToken(); return parser; } @@ -251,7 +251,7 @@ private XContentParser stringLatLon(double lat, double lon) throws IOException { private XContentParser geohash(double lat, double lon) throws IOException { XContentBuilder content = JsonXContent.contentBuilder(); content.value(stringEncode(lon, lat)); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(content)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(content)); parser.nextToken(); return parser; } diff --git a/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java b/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java index 646b3b7692b48..3b4db9e7a5a3c 100644 --- a/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java +++ b/server/src/test/java/org/opensearch/index/snapshots/blobstore/FileInfoTests.java @@ -36,7 +36,6 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.unit.ByteSizeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -76,7 +75,7 @@ public void testToFromXContent() throws IOException { BlobStoreIndexShardSnapshot.FileInfo info = new BlobStoreIndexShardSnapshot.FileInfo("_foobar", meta, size); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); BlobStoreIndexShardSnapshot.FileInfo.toXContent(info, builder, ToXContent.EMPTY_PARAMS); - byte[] xcontent = BytesReference.toBytes(BytesReferenceUtil.bytes(shuffleXContent(builder))); + byte[] xcontent = BytesReference.toBytes(BytesReference.bytes(shuffleXContent(builder))); final BlobStoreIndexShardSnapshot.FileInfo parsedInfo; try (XContentParser parser = createParser(JsonXContent.jsonXContent, xcontent)) { @@ -135,7 +134,7 @@ public void testInvalidFieldsInFromXContent() throws IOException { builder.field(FileInfo.WRITTEN_BY, Version.LATEST.toString()); builder.field(FileInfo.CHECKSUM, "666"); builder.endObject(); - byte[] xContent = BytesReference.toBytes(BytesReferenceUtil.bytes(builder)); + byte[] xContent = BytesReference.toBytes(BytesReference.bytes(builder)); if (failure == null) { // No failures should read as usual diff --git a/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java b/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java index 20c14a6b92775..1cb6579c0f1f2 100644 --- a/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java +++ b/server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java @@ -10,7 +10,6 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -198,7 +197,7 @@ public void testFromXContentInvalid() throws IOException { } builder.endArray(); builder.endObject(); - byte[] xContent = BytesReference.toBytes(BytesReferenceUtil.bytes(builder)); + byte[] xContent = BytesReference.toBytes(BytesReference.bytes(builder)); if (failure == null) { // No failures should read as usual diff --git a/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java b/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java index 561970c3766f7..78350b7ab4c04 100644 --- a/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java +++ b/server/src/test/java/org/opensearch/ingest/PipelineConfigurationTests.java @@ -36,7 +36,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ContextParser; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -78,7 +77,7 @@ public void testParser() throws IOException { builder, ToXContent.EMPTY_PARAMS ); - bytes = BytesReferenceUtil.bytes(builder); + bytes = BytesReference.bytes(builder); } XContentParser xContentParser = xContentType.xContent() diff --git a/server/src/test/java/org/opensearch/repositories/IndexIdTests.java b/server/src/test/java/org/opensearch/repositories/IndexIdTests.java index c12d315c0a569..3554f2743698a 100644 --- a/server/src/test/java/org/opensearch/repositories/IndexIdTests.java +++ b/server/src/test/java/org/opensearch/repositories/IndexIdTests.java @@ -33,8 +33,8 @@ package org.opensearch.repositories; import org.opensearch.common.UUIDs; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -82,7 +82,7 @@ public void testXContent() throws IOException { IndexId indexId = new IndexId(randomAlphaOfLength(8), UUIDs.randomBase64UUID()); XContentBuilder builder = JsonXContent.contentBuilder(); indexId.toXContent(builder, ToXContent.EMPTY_PARAMS); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); String name = null; String id = null; diff --git a/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java b/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java index 5d30e7a3da530..8d76f4a91837d 100644 --- a/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java +++ b/server/src/test/java/org/opensearch/repositories/RepositoryDataTests.java @@ -35,7 +35,7 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.Version; import org.opensearch.common.UUIDs; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -93,7 +93,7 @@ public void testXContent() throws IOException { RepositoryData repositoryData = generateRandomRepoData(); XContentBuilder builder = JsonXContent.contentBuilder(); repositoryData.snapshotsToXContent(builder, Version.CURRENT); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { long gen = (long) randomIntBetween(0, 500); RepositoryData fromXContent = RepositoryData.snapshotsFromXContent(parser, gen); assertEquals(repositoryData, fromXContent); diff --git a/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java b/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java index cc070ba9c9c38..ae6352a6c6636 100644 --- a/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java +++ b/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java @@ -41,8 +41,8 @@ import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.ShardSearchFailure; import org.opensearch.common.ParsingException; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.transport.TransportAddress; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -348,7 +348,7 @@ public void testNoErrorFromXContent() throws IOException { builder.field("status", randomFrom(RestStatus.values()).getStatus()); builder.endObject(); - try (XContentParser parser = createParser(builder.contentType().xContent(), BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(builder.contentType().xContent(), BytesReference.bytes(builder))) { BytesRestResponse.errorFromXContent(parser); } } diff --git a/server/src/test/java/org/opensearch/rest/RestControllerTests.java b/server/src/test/java/org/opensearch/rest/RestControllerTests.java index a2ca3b092ed4b..489419fc24526 100644 --- a/server/src/test/java/org/opensearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/opensearch/rest/RestControllerTests.java @@ -42,7 +42,6 @@ import org.opensearch.common.transport.BoundTransportAddress; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.unit.ByteSizeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentType; @@ -478,7 +477,7 @@ public boolean supportsContentStream() { public void testNonStreamingXContentCausesErrorResponse() throws IOException { FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent( - BytesReferenceUtil.bytes(YamlXContent.contentBuilder().startObject().endObject()), + BytesReference.bytes(YamlXContent.contentBuilder().startObject().endObject()), XContentType.YAML ).withPath("/foo").build(); AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); diff --git a/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java b/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java index 243ebc54b47e8..b128a3e30166f 100644 --- a/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/RestMainActionTests.java @@ -37,7 +37,6 @@ import org.opensearch.action.main.MainResponse; import org.opensearch.cluster.ClusterName; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.json.JsonXContent; @@ -107,7 +106,7 @@ public void testGetResponse() throws Exception { responseBuilder.prettyPrint().lfAtEnd(); } mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS); - BytesReference xcontentBytes = BytesReferenceUtil.bytes(responseBuilder); + BytesReference xcontentBytes = BytesReference.bytes(responseBuilder); assertEquals(xcontentBytes, response.content()); } } diff --git a/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java index 7e60dfec1541d..047fe0f286393 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/indices/RestCreateIndexActionTests.java @@ -32,7 +32,7 @@ package org.opensearch.rest.action.admin.indices; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; @@ -62,7 +62,7 @@ public void testPrepareTypelessRequest() throws IOException { .endObject() .endObject(); - Map contentAsMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(content), true, content.contentType()).v2(); + Map contentAsMap = XContentHelper.convertToMap(BytesReference.bytes(content), true, content.contentType()).v2(); Map source = RestCreateIndexAction.prepareMappings(contentAsMap); XContentBuilder expectedContent = XContentFactory.jsonBuilder() @@ -85,7 +85,7 @@ public void testPrepareTypelessRequest() throws IOException { .endObject() .endObject(); Map expectedContentAsMap = XContentHelper.convertToMap( - BytesReferenceUtil.bytes(expectedContent), + BytesReference.bytes(expectedContent), true, expectedContent.contentType() ).v2(); @@ -103,7 +103,7 @@ public void testMalformedMappings() throws IOException { .endObject() .endObject(); - Map contentAsMap = XContentHelper.convertToMap(BytesReferenceUtil.bytes(content), true, content.contentType()).v2(); + Map contentAsMap = XContentHelper.convertToMap(BytesReference.bytes(content), true, content.contentType()).v2(); Map source = RestCreateIndexAction.prepareMappings(contentAsMap); assertEquals(contentAsMap, source); diff --git a/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java b/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java index db3e0fc70c64d..9c139f6de573f 100644 --- a/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java +++ b/server/src/test/java/org/opensearch/script/ScriptMetadataTests.java @@ -33,8 +33,8 @@ import org.opensearch.cluster.DiffableUtils; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -57,7 +57,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); expectThrows(IllegalArgumentException.class, () -> ScriptMetadata.fromXContent(parser0)); @@ -74,7 +74,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); expectThrows(IllegalArgumentException.class, () -> ScriptMetadata.fromXContent(parser1)); @@ -96,7 +96,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); expectThrows(IllegalArgumentException.class, () -> ScriptMetadata.fromXContent(parser2)); @@ -113,7 +113,7 @@ public void testFromXContentLoading() throws Exception { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser3); } @@ -131,12 +131,12 @@ public void testGetScript() throws Exception { .endObject() .endObject(); XContentType xContentType = XContentType.fromMediaType(sourceBuilder.contentType()); - builder.storeScript("source_template", StoredScriptSource.parse(BytesReferenceUtil.bytes(sourceBuilder), xContentType)); + builder.storeScript("source_template", StoredScriptSource.parse(BytesReference.bytes(sourceBuilder), xContentType)); sourceBuilder = XContentFactory.jsonBuilder(); xContentType = XContentType.fromMediaType(sourceBuilder.contentType()); sourceBuilder.startObject().startObject("script").field("lang", "_lang").field("source", "_source").endObject().endObject(); - builder.storeScript("script", StoredScriptSource.parse(BytesReferenceUtil.bytes(sourceBuilder), xContentType)); + builder.storeScript("script", StoredScriptSource.parse(BytesReference.bytes(sourceBuilder), xContentType)); ScriptMetadata scriptMetadata = builder.build(); assertEquals("_source", scriptMetadata.getStoredScript("script").getSource()); @@ -206,7 +206,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertWarnings("empty templates should no longer be used"); @@ -217,7 +217,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertWarnings("empty scripts should no longer be used"); @@ -228,7 +228,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertNoDeprecationWarnings(); @@ -239,7 +239,7 @@ public void testLoadEmptyScripts() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); ScriptMetadata.fromXContent(parser); assertNoDeprecationWarnings(); @@ -275,7 +275,7 @@ public void testOldStyleDropped() throws IOException { .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder).streamInput() + BytesReference.bytes(builder).streamInput() ); ScriptMetadata smd = ScriptMetadata.fromXContent(parser); assertNull(smd.getStoredScript("painless#test")); @@ -303,7 +303,7 @@ private ScriptMetadata randomScriptMetadata(XContentType sourceContentType, int .endObject(); builder.storeScript( randomAlphaOfLength(i + 1), - StoredScriptSource.parse(BytesReferenceUtil.bytes(sourceBuilder), XContentType.fromMediaType(sourceBuilder.contentType())) + StoredScriptSource.parse(BytesReference.bytes(sourceBuilder), XContentType.fromMediaType(sourceBuilder.contentType())) ); } return builder.build(); diff --git a/server/src/test/java/org/opensearch/script/ScriptServiceTests.java b/server/src/test/java/org/opensearch/script/ScriptServiceTests.java index 7b15ffcd1ad0c..0485fc9935f15 100644 --- a/server/src/test/java/org/opensearch/script/ScriptServiceTests.java +++ b/server/src/test/java/org/opensearch/script/ScriptServiceTests.java @@ -43,7 +43,6 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.env.Environment; @@ -366,7 +365,7 @@ public void testContextCacheStats() throws IOException { } public void testStoreScript() throws Exception { - BytesReference script = BytesReferenceUtil.bytes( + BytesReference script = BytesReference.bytes( XContentFactory.jsonBuilder() .startObject() .field("script") diff --git a/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java b/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java index 2309bbae31f67..1f33a51c9253c 100644 --- a/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java +++ b/server/src/test/java/org/opensearch/script/StoredScriptSourceTests.java @@ -33,8 +33,8 @@ package org.opensearch.script; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable.Reader; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -66,7 +66,7 @@ protected StoredScriptSource createTestInstance() { if (randomBoolean()) { options.put(Script.CONTENT_TYPE_OPTION, xContentType.mediaType()); } - return StoredScriptSource.parse(BytesReferenceUtil.bytes(template), xContentType); + return StoredScriptSource.parse(BytesReference.bytes(template), xContentType); } catch (IOException e) { throw new AssertionError("Failed to create test instance", e); } diff --git a/server/src/test/java/org/opensearch/script/StoredScriptTests.java b/server/src/test/java/org/opensearch/script/StoredScriptTests.java index 8dfdeff29b8f4..a943920dc1451 100644 --- a/server/src/test/java/org/opensearch/script/StoredScriptTests.java +++ b/server/src/test/java/org/opensearch/script/StoredScriptTests.java @@ -35,8 +35,8 @@ import org.opensearch.ResourceNotFoundException; import org.opensearch.common.ParsingException; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; @@ -76,7 +76,7 @@ public void testSourceParsing() throws Exception { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().startObject("script").field("lang", "lang").field("source", "code").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -98,7 +98,7 @@ public void testSourceParsing() throws Exception { code = Strings.toString(cb.startObject().field("query", "code").endObject()); } - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource( "mustache", code, @@ -112,7 +112,7 @@ public void testSourceParsing() throws Exception { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "lang").field("source", "code").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -122,7 +122,7 @@ public void testSourceParsing() throws Exception { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -142,7 +142,7 @@ public void testSourceParsing() throws Exception { .endObject() .endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource("lang", "code", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -169,7 +169,7 @@ public void testSourceParsing() throws Exception { code = Strings.toString(cb.startObject().field("query", "code").endObject()); } - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource( "lang", code, @@ -187,7 +187,7 @@ public void testSourceParsingErrors() throws Exception { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, - () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) ); assertThat(iae.getMessage(), equalTo("must specify lang for stored script")); } @@ -198,7 +198,7 @@ public void testSourceParsingErrors() throws Exception { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, - () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) ); assertThat(iae.getMessage(), equalTo("must specify source for stored script")); } @@ -218,7 +218,7 @@ public void testSourceParsingErrors() throws Exception { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, - () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) ); assertThat(iae.getMessage(), equalTo("illegal compiler options [{option=option}] specified")); } @@ -228,7 +228,7 @@ public void testSourceParsingErrors() throws Exception { builder.startObject().field("template", "code").endObject(); ParsingException pEx = expectThrows( ParsingException.class, - () -> StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON) + () -> StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON) ); assertThat( pEx.getMessage(), @@ -241,7 +241,7 @@ public void testEmptyTemplateDeprecations() throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource(Script.DEFAULT_TEMPLATE_LANG, "", Collections.emptyMap()); assertThat(parsed, equalTo(source)); @@ -251,7 +251,7 @@ public void testEmptyTemplateDeprecations() throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) { builder.startObject().field("script").startObject().field("lang", "mustache").field("source", "").endObject().endObject(); - StoredScriptSource parsed = StoredScriptSource.parse(BytesReferenceUtil.bytes(builder), XContentType.JSON); + StoredScriptSource parsed = StoredScriptSource.parse(BytesReference.bytes(builder), XContentType.JSON); StoredScriptSource source = new StoredScriptSource(Script.DEFAULT_TEMPLATE_LANG, "", Collections.emptyMap()); assertThat(parsed, equalTo(source)); diff --git a/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java b/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java index 334b6cf0c3f05..e94b8ccf83c1f 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/AggregationsTests.java @@ -34,7 +34,6 @@ import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContent; @@ -278,7 +277,7 @@ public void testParsingExceptionOnUnknownAggregation() throws IOException { builder.endObject(); } builder.endObject(); - BytesReference originalBytes = BytesReferenceUtil.bytes(builder); + BytesReference originalBytes = BytesReference.bytes(builder); try (XContentParser parser = createParser(builder.contentType().xContent(), originalBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); ParsingException ex = expectThrows(ParsingException.class, () -> Aggregations.fromXContent(parser)); diff --git a/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java b/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java index f2c2ec4519558..6e83739ac8771 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java @@ -37,7 +37,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -250,7 +249,7 @@ public void testRewriteAggregation() throws Exception { builder.endObject(); } builder.endObject(); - bytesReference = BytesReferenceUtil.bytes(builder); + bytesReference = BytesReference.bytes(builder); } FilterAggregationBuilder filterAggBuilder = new FilterAggregationBuilder("titles", new WrapperQueryBuilder(bytesReference)); BucketScriptPipelineAggregationBuilder pipelineAgg = new BucketScriptPipelineAggregationBuilder("const", new Script("1")); diff --git a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java index d3f96451d40cc..3d62f3a93e70b 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/DoubleBoundsTests.java @@ -35,7 +35,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -101,7 +100,7 @@ public void testXContentRoundTrip() throws Exception { orig.toXContent(out, ToXContent.EMPTY_PARAMS); out.endObject(); - try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(out))) { + try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReference.bytes(out))) { XContentParser.Token token = in.currentToken(); assertNull(token); @@ -111,7 +110,7 @@ public void testXContentRoundTrip() throws Exception { DoubleBounds read = DoubleBounds.PARSER.apply(in, null); assertEquals(orig, read); } catch (Exception e) { - throw new Exception("Error parsing [" + BytesReferenceUtil.bytes(out).utf8ToString() + "]", e); + throw new Exception("Error parsing [" + BytesReference.bytes(out).utf8ToString() + "]", e); } } } diff --git a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java index c71e3941501d8..e927488edd920 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/bucket/histogram/LongBoundsTests.java @@ -40,7 +40,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.time.DateFormatter; import org.opensearch.common.util.BigArrays; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -199,7 +198,7 @@ public void testXContentRoundTrip() throws Exception { orig.toXContent(out, ToXContent.EMPTY_PARAMS); out.endObject(); - try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(out))) { + try (XContentParser in = createParser(JsonXContent.jsonXContent, BytesReference.bytes(out))) { XContentParser.Token token = in.currentToken(); assertNull(token); @@ -209,7 +208,7 @@ public void testXContentRoundTrip() throws Exception { LongBounds read = LongBounds.PARSER.apply(in, null); assertEquals(orig, read); } catch (Exception e) { - throw new Exception("Error parsing [" + BytesReferenceUtil.bytes(out).utf8ToString() + "]", e); + throw new Exception("Error parsing [" + BytesReference.bytes(out).utf8ToString() + "]", e); } } } diff --git a/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java b/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java index d59dd760d22b6..2608c2dee0a23 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/metrics/InternalTopHitsTests.java @@ -41,10 +41,10 @@ import org.apache.lucene.search.TopFieldDocs; import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.BytesRef; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; import org.opensearch.common.document.DocumentField; import org.opensearch.common.lucene.search.TopDocsAndMaxScore; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -327,8 +327,8 @@ private static void assertEqualsWithErrorMessageFromXCont expectedJson.endObject(); NotEqualMessageBuilder message = new NotEqualMessageBuilder(); message.compareMaps( - XContentHelper.convertToMap(BytesReferenceUtil.bytes(actualJson), false).v2(), - XContentHelper.convertToMap(BytesReferenceUtil.bytes(expectedJson), false).v2() + XContentHelper.convertToMap(BytesReference.bytes(actualJson), false).v2(), + XContentHelper.convertToMap(BytesReference.bytes(expectedJson), false).v2() ); throw new AssertionError("Didn't match expected value:\n" + message); } catch (IOException e) { diff --git a/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java b/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java index 9c9e71f3367ae..09c4fbc1ba251 100644 --- a/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java +++ b/server/src/test/java/org/opensearch/search/builder/SearchSourceBuilderTests.java @@ -39,7 +39,6 @@ import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -428,7 +427,7 @@ public void testToXContent() throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); XContentBuilder builder = XContentFactory.contentBuilder(xContentType); searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - BytesReference source = BytesReferenceUtil.bytes(builder); + BytesReference source = BytesReference.bytes(builder); Map sourceAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); assertEquals(0, sourceAsMap.size()); } @@ -437,7 +436,7 @@ public void testToXContent() throws IOException { searchSourceBuilder.query(RandomQueryBuilder.createQuery(random())); XContentBuilder builder = XContentFactory.contentBuilder(xContentType); searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - BytesReference source = BytesReferenceUtil.bytes(builder); + BytesReference source = BytesReference.bytes(builder); Map sourceAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); assertEquals(1, sourceAsMap.size()); assertEquals("query", sourceAsMap.keySet().iterator().next()); @@ -451,7 +450,7 @@ public void testToXContentWithPointInTime() throws IOException { searchSourceBuilder.pointInTimeBuilder(new PointInTimeBuilder("id").setKeepAlive(keepAlive)); XContentBuilder builder = XContentFactory.contentBuilder(xContentType); searchSourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); - BytesReference bytes = BytesReferenceUtil.bytes(builder); + BytesReference bytes = BytesReference.bytes(builder); Map sourceAsMap = XContentHelper.convertToMap(bytes, false, xContentType).v2(); assertEquals(1, sourceAsMap.size()); @SuppressWarnings("unchecked") diff --git a/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java b/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java index ab9c9a748ed04..7356e64ed329b 100644 --- a/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java +++ b/server/src/test/java/org/opensearch/search/fetch/subphase/FetchSourcePhaseTests.java @@ -34,7 +34,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.memory.MemoryIndex; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.XContentBuilder; @@ -196,7 +196,7 @@ private HitContext hitExecuteMultiple( MemoryIndex index = new MemoryIndex(); LeafReaderContext leafReaderContext = index.createSearcher().getIndexReader().leaves().get(0); HitContext hitContext = new HitContext(searchHit, leafReaderContext, 1, new SourceLookup()); - hitContext.sourceLookup().setSource(source == null ? null : BytesReferenceUtil.bytes(source)); + hitContext.sourceLookup().setSource(source == null ? null : BytesReference.bytes(source)); FetchSourcePhase phase = new FetchSourcePhase(); FetchSubPhaseProcessor processor = phase.getProcessor(fetchContext); diff --git a/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java b/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java index d44a17033b328..f6d5789c1d503 100644 --- a/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java +++ b/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java @@ -34,9 +34,9 @@ import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.document.DocumentField; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.index.IndexService; @@ -446,7 +446,7 @@ private static Map fetchFields(MapperService mapperServic throws IOException { SourceLookup sourceLookup = new SourceLookup(); - sourceLookup.setSource(BytesReferenceUtil.bytes(source)); + sourceLookup.setSource(BytesReference.bytes(source)); FieldFetcher fieldFetcher = FieldFetcher.create(createQueryShardContext(mapperService), null, fields); return fieldFetcher.fetch(sourceLookup, Set.of()); diff --git a/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java b/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java index 99408af0a01b2..ca4cb7291b862 100644 --- a/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java +++ b/server/src/test/java/org/opensearch/search/searchafter/SearchAfterBuilderTests.java @@ -37,11 +37,11 @@ import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.search.SortedSetSortField; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.text.Text; import org.opensearch.common.util.BigArrays; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; @@ -158,7 +158,7 @@ private SearchAfterBuilder randomJsonSearchFromBuilder() throws IOException { } jsonBuilder.endArray(); jsonBuilder.endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(jsonBuilder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(jsonBuilder))) { parser.nextToken(); parser.nextToken(); parser.nextToken(); diff --git a/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java b/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java index 873050492291d..636593f9a7d80 100644 --- a/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/SuggestTests.java @@ -33,7 +33,6 @@ package org.opensearch.search.suggest; import org.opensearch.Version; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesReference; @@ -235,7 +234,7 @@ public void testParsingExceptionOnUnknownSuggestion() throws IOException { builder.endArray(); } builder.endObject(); - BytesReference originalBytes = BytesReferenceUtil.bytes(builder); + BytesReference originalBytes = BytesReference.bytes(builder); try (XContentParser parser = createParser(builder.contentType().xContent(), originalBytes)) { assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); ParsingException ex = expectThrows(ParsingException.class, () -> Suggest.fromXContent(parser)); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java index 89f92f81a379e..248c5280ae54c 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java @@ -42,9 +42,9 @@ import org.apache.lucene.search.suggest.document.ContextSuggestField; import org.apache.lucene.util.BytesRef; import org.opensearch.common.Strings; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParseException; import org.opensearch.core.xcontent.XContentParser; @@ -99,7 +99,7 @@ public void testIndexingWithNoContexts() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -149,7 +149,7 @@ public void testIndexingWithSimpleContexts() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -194,7 +194,7 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -239,7 +239,7 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -293,7 +293,7 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { Exception e = expectThrows( MapperParsingException.class, - () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON)) + () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)) ); assertEquals( "contexts must be a string, number or boolean or a list of string, number or boolean, but was [VALUE_NULL]", @@ -326,7 +326,7 @@ public void testIndexingWithContextList() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -369,7 +369,7 @@ public void testIndexingWithMixedTypeContextList() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -419,7 +419,7 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { Exception e = expectThrows( MapperParsingException.class, - () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON)) + () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)) ); assertEquals("context array must have string, number or boolean values, but was [VALUE_NULL]", e.getCause().getMessage()); } @@ -462,7 +462,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = defaultMapper.parse( - new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON) + new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON) ); IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name()); assertContextSuggestFields(fields, 3); @@ -470,7 +470,7 @@ public void testIndexingWithMultipleContexts() throws Exception { public void testQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().value("context1"); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -482,7 +482,7 @@ public void testQueryContextParsingBasic() throws Exception { public void testBooleanQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().value(true); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -494,7 +494,7 @@ public void testBooleanQueryContextParsingBasic() throws Exception { public void testNumberQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().value(10); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -506,7 +506,7 @@ public void testNumberQueryContextParsingBasic() throws Exception { public void testNULLQueryContextParsingBasic() throws Exception { XContentBuilder builder = jsonBuilder().nullValue(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -516,7 +516,7 @@ public void testNULLQueryContextParsingBasic() throws Exception { public void testQueryContextParsingArray() throws Exception { XContentBuilder builder = jsonBuilder().startArray().value("context1").value("context2").endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(2)); @@ -531,7 +531,7 @@ public void testQueryContextParsingArray() throws Exception { public void testQueryContextParsingMixedTypeValuesArray() throws Exception { XContentBuilder builder = jsonBuilder().startArray().value("context1").value("context2").value(true).value(10).endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(4)); @@ -558,7 +558,7 @@ public void testQueryContextParsingMixedTypeValuesArrayHavingNULL() throws Excep .value(10) .nullValue() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -572,7 +572,7 @@ public void testQueryContextParsingObject() throws Exception { .field("boost", 10) .field("prefix", true) .endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -584,7 +584,7 @@ public void testQueryContextParsingObject() throws Exception { public void testQueryContextParsingObjectHavingBoolean() throws Exception { XContentBuilder builder = jsonBuilder().startObject().field("context", false).field("boost", 10).field("prefix", true).endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -596,7 +596,7 @@ public void testQueryContextParsingObjectHavingBoolean() throws Exception { public void testQueryContextParsingObjectHavingNumber() throws Exception { XContentBuilder builder = jsonBuilder().startObject().field("context", 333).field("boost", 10).field("prefix", true).endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1)); @@ -608,7 +608,7 @@ public void testQueryContextParsingObjectHavingNumber() throws Exception { public void testQueryContextParsingObjectHavingNULL() throws Exception { XContentBuilder builder = jsonBuilder().startObject().nullField("context").field("boost", 10).field("prefix", true).endObject(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); Exception e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -629,7 +629,7 @@ public void testQueryContextParsingObjectArray() throws Exception { .field("prefix", false) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(2)); @@ -665,7 +665,7 @@ public void testQueryContextParsingMixedTypeObjectArray() throws Exception { .field("prefix", false) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(4)); @@ -712,7 +712,7 @@ public void testQueryContextParsingMixedTypeObjectArrayHavingNULL() throws Excep .field("prefix", false) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); @@ -735,7 +735,7 @@ public void testQueryContextParsingMixed() throws Exception { .field("prefix", true) .endObject() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(4)); @@ -770,7 +770,7 @@ public void testQueryContextParsingMixedHavingNULL() throws Exception { .endObject() .nullValue() .endArray(); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder))) { + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { CategoryContextMapping mapping = ContextBuilder.category("cat").build(); XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser)); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java index 7823a74a398d5..fb6cce3f8e9ab 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java @@ -34,8 +34,8 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.OpenSearchParseException; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -84,7 +84,7 @@ public void testIndexingWithNoContexts() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -131,7 +131,7 @@ public void testIndexingWithSimpleContexts() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startArray("completion") .startObject() @@ -176,7 +176,7 @@ public void testIndexingWithContextList() throws Exception { new SourceToParse( "test", "1", - BytesReferenceUtil.bytes( + BytesReference.bytes( jsonBuilder().startObject() .startObject("completion") .array("input", "suggestion5", "suggestion6", "suggestion7") @@ -237,7 +237,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endArray() .endObject(); ParsedDocument parsedDocument = mapperService.documentMapper() - .parse(new SourceToParse("test", "1", BytesReferenceUtil.bytes(builder), XContentType.JSON)); + .parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)); IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name()); assertContextSuggestFields(fields, 3); } @@ -308,7 +308,7 @@ public void testMissingGeoField() throws Exception { public void testParsingQueryContextBasic() throws Exception { XContentBuilder builder = jsonBuilder().value("ezs42e44yx96"); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 8)); @@ -324,7 +324,7 @@ public void testParsingQueryContextBasic() throws Exception { public void testParsingQueryContextGeoPoint() throws Exception { XContentBuilder builder = jsonBuilder().startObject().field("lat", 23.654242).field("lon", 90.047153).endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 8)); @@ -347,7 +347,7 @@ public void testParsingQueryContextObject() throws Exception { .field("boost", 10) .array("neighbours", 1, 2, 3) .endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8)); @@ -385,7 +385,7 @@ public void testParsingQueryContextObjectArray() throws Exception { .array("neighbours", 5) .endObject() .endArray(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 1 + 8)); @@ -428,7 +428,7 @@ public void testParsingQueryContextMixed() throws Exception { .field("lon", 92.112583) .endObject() .endArray(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); List internalQueryContexts = mapping.parseQueryContext(parser); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8)); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java index 7deea5a2e66e6..377601c5ed435 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/GeoQueryContextTests.java @@ -32,8 +32,8 @@ package org.opensearch.search.suggest.completion; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.geo.GeoPoint; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -133,7 +133,7 @@ public void testStringPrecision() throws IOException { builder.array("neighbours", 1, 2); } builder.endObject(); - XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); parser.nextToken(); GeoQueryContext queryContext = fromXContent(parser); assertEquals(10, queryContext.getBoost()); @@ -148,7 +148,7 @@ public void testStringPrecision() throws IOException { builder.array("neighbours", "4km", "10km"); } builder.endObject(); - parser = createParser(JsonXContent.jsonXContent, BytesReferenceUtil.bytes(builder)); + parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); parser.nextToken(); queryContext = fromXContent(parser); assertEquals(10, queryContext.getBoost()); diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java index fcca5450152a0..b18aa6c53c107 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotRequestsTests.java @@ -36,7 +36,6 @@ import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; import org.opensearch.action.support.IndicesOptions; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.test.OpenSearchTestCase; @@ -95,7 +94,7 @@ public void testRestoreSnapshotRequestParsing() throws IOException { builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable()); } - BytesReference bytes = BytesReferenceUtil.bytes(builder.endObject()); + BytesReference bytes = BytesReference.bytes(builder.endObject()); request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2()); @@ -161,7 +160,7 @@ public void testCreateSnapshotRequestParsing() throws IOException { builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable()); } - BytesReference bytes = BytesReferenceUtil.bytes(builder.endObject()); + BytesReference bytes = BytesReference.bytes(builder.endObject()); request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2()); diff --git a/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java b/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java index 1a99ac0ee947e..0ba8ea13cc71c 100644 --- a/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java +++ b/server/src/test/java/org/opensearch/tasks/TaskInfoTests.java @@ -33,9 +33,9 @@ package org.opensearch.tasks; import org.opensearch.client.Requests; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.test.AbstractSerializingTestCase; @@ -348,7 +348,7 @@ private static RawTaskStatus randomRawTaskStatus() { builder.field(randomAlphaOfLength(5), randomAlphaOfLength(5)); } builder.endObject(); - return new RawTaskStatus(BytesReferenceUtil.bytes(builder)); + return new RawTaskStatus(BytesReference.bytes(builder)); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java b/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java index ccf8721288969..f268b80edb44c 100644 --- a/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java +++ b/server/src/test/java/org/opensearch/threadpool/ThreadPoolSerializationTests.java @@ -32,12 +32,12 @@ package org.opensearch.threadpool; import org.opensearch.Version; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.SizeValue; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -98,7 +98,7 @@ public void testThatToXContentWritesOutUnboundedCorrectly() throws Exception { info.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - Map map = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + Map map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); assertThat(map, hasKey("foo")); map = (Map) map.get("foo"); assertThat(map, hasKey("queue_size")); @@ -126,7 +126,7 @@ public void testThatToXContentWritesInteger() throws Exception { info.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - Map map = XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + Map map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); assertThat(map, hasKey("foo")); map = (Map) map.get("foo"); assertThat(map, hasKey("queue_size")); diff --git a/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java b/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java index 8c1936922b718..9370a2a211725 100644 --- a/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/engine/EngineTestCase.java @@ -82,7 +82,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.BigArrays; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.set.Sets; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -451,7 +450,7 @@ public static CheckedBiFunction ne source.endObject(); } source.endObject(); - return nestedMapper.parse(new SourceToParse("test", docId, BytesReferenceUtil.bytes(source), XContentType.JSON)); + return nestedMapper.parse(new SourceToParse("test", docId, BytesReference.bytes(source), XContentType.JSON)); }; } diff --git a/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java b/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java index 58e3812279a95..30cbe5dcc6091 100644 --- a/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/mapper/MapperServiceTestCase.java @@ -41,9 +41,9 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.bytes.BytesArray; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -185,7 +185,7 @@ protected final SourceToParse source(CheckedConsumer buildFields) throws IOException { diff --git a/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java b/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java index 3654753ccc999..420cb5f86e95f 100644 --- a/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java @@ -45,7 +45,7 @@ import org.opensearch.common.CheckedConsumer; import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; @@ -235,14 +235,14 @@ public void testMeta() throws IOException { }); MapperService mapperService = createMapperService(mapping); assertEquals( - XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), false, mapping.contentType()).v2(), + XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(), XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2() ); mapping = fieldMapping(this::metaMapping); merge(mapperService, mapping); assertEquals( - XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), false, mapping.contentType()).v2(), + XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(), XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2() ); @@ -252,7 +252,7 @@ public void testMeta() throws IOException { }); merge(mapperService, mapping); assertEquals( - XContentHelper.convertToMap(BytesReferenceUtil.bytes(mapping), false, mapping.contentType()).v2(), + XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(), XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2() ); } diff --git a/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java b/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java index 2cabcb5420361..9dec1f2ba739c 100644 --- a/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java +++ b/test/framework/src/main/java/org/opensearch/search/RandomSearchRequestGenerator.java @@ -35,9 +35,9 @@ import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchType; import org.opensearch.action.support.IndicesOptions; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.text.Text; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.FeatureFlags; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -358,7 +358,7 @@ public static SearchSourceBuilder randomSearchSourceBuilder( .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(jsonBuilder).streamInput() + BytesReference.bytes(jsonBuilder).streamInput() ); parser.nextToken(); parser.nextToken(); diff --git a/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java b/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java index ad3fcaf23c8e7..9933297aa1c96 100644 --- a/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -56,7 +56,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -429,9 +428,7 @@ protected String initWithSnapshotVersion(String repoName, Path repoPath, Version ); Files.write( repoPath.resolve(BlobStoreRepository.INDEX_FILE_PREFIX + repositoryData.getGenId()), - BytesReference.toBytes( - BytesReferenceUtil.bytes(downgradedRepoData.snapshotsToXContent(XContentFactory.jsonBuilder(), version)) - ), + BytesReference.toBytes(BytesReference.bytes(downgradedRepoData.snapshotsToXContent(XContentFactory.jsonBuilder(), version))), StandardOpenOption.TRUNCATE_EXISTING ); return oldVersionSnapshot; diff --git a/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java b/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java index ee3edf855a2c1..d2dfa4ef628e5 100644 --- a/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/AbstractXContentTestCase.java @@ -36,7 +36,6 @@ import org.opensearch.common.CheckedBiFunction; import org.opensearch.common.CheckedFunction; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.common.Strings; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContent; @@ -66,7 +65,7 @@ public static XContentTester xContentTester( return new XContentTester<>(createParser, x -> instanceSupplier.get(), (testInstance, xContentType) -> { try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { toXContent.accept(testInstance, builder); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } }, fromXContent); } @@ -307,7 +306,7 @@ static BytesReference insertRandomFieldsAndShuffle( withRandomFields = xContent; } XContentParser parserWithRandonFields = createParserFunction.apply(XContentFactory.xContent(xContentType), withRandomFields); - return BytesReferenceUtil.bytes(shuffleXContent(parserWithRandonFields, false, shuffleFieldsExceptions)); + return BytesReference.bytes(shuffleXContent(parserWithRandonFields, false, shuffleFieldsExceptions)); } } diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java index 9ad2ddac203dc..4474aae1f0631 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java @@ -109,7 +109,6 @@ import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -1203,13 +1202,13 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); metadataWithoutIndices.toXContent(builder, serializationFormatParams); builder.endObject(); - final BytesReference originalBytes = BytesReferenceUtil.bytes(builder); + final BytesReference originalBytes = BytesReference.bytes(builder); XContentBuilder compareBuilder = SmileXContent.contentBuilder(); compareBuilder.startObject(); metadataWithoutIndices.toXContent(compareBuilder, compareFormatParams); compareBuilder.endObject(); - final BytesReference compareOriginalBytes = BytesReferenceUtil.bytes(compareBuilder); + final BytesReference compareOriginalBytes = BytesReference.bytes(compareBuilder); final Metadata loadedMetadata; try ( @@ -1225,7 +1224,7 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); loadedMetadata.toXContent(builder, compareFormatParams); builder.endObject(); - final BytesReference parsedBytes = BytesReferenceUtil.bytes(builder); + final BytesReference parsedBytes = BytesReference.bytes(builder); assertNull( "cluster state XContent serialization does not match, expected " @@ -1244,13 +1243,13 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); indexMetadata.toXContent(builder, serializationFormatParams); builder.endObject(); - final BytesReference originalBytes = BytesReferenceUtil.bytes(builder); + final BytesReference originalBytes = BytesReference.bytes(builder); XContentBuilder compareBuilder = SmileXContent.contentBuilder(); compareBuilder.startObject(); indexMetadata.toXContent(compareBuilder, compareFormatParams); compareBuilder.endObject(); - final BytesReference compareOriginalBytes = BytesReferenceUtil.bytes(compareBuilder); + final BytesReference compareOriginalBytes = BytesReference.bytes(compareBuilder); final IndexMetadata loadedIndexMetadata; try ( @@ -1266,7 +1265,7 @@ protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { builder.startObject(); loadedIndexMetadata.toXContent(builder, compareFormatParams); builder.endObject(); - final BytesReference parsedBytes = BytesReferenceUtil.bytes(builder); + final BytesReference parsedBytes = BytesReference.bytes(builder); assertNull( "cluster state XContent serialization does not match, expected " diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java index 895bc8b88139a..7722b59313b5f 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java @@ -90,7 +90,6 @@ import org.opensearch.common.time.DateUtils; import org.opensearch.common.time.FormatNames; import org.opensearch.common.transport.TransportAddress; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.common.util.MockBigArrays; import org.opensearch.common.util.MockPageCacheRecycler; import org.opensearch.common.util.concurrent.ThreadContext; @@ -1287,7 +1286,7 @@ protected final BytesReference toShuffledXContent( BytesReference bytes = XContentHelper.toXContent(toXContent, xContentType, params, humanReadable); try (XContentParser parser = createParser(xContentType.xContent(), bytes)) { try (XContentBuilder builder = shuffleXContent(parser, rarely(), exceptFieldNames)) { - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } } @@ -1307,7 +1306,7 @@ protected final BytesReference toShuffledXContent( BytesReference bytes = XContentHelper.toXContent(toXContent, mediaType, params, humanReadable); try (XContentParser parser = createParser(mediaType.xContent(), bytes)) { try (XContentBuilder builder = shuffleXContent(parser, rarely(), exceptFieldNames)) { - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } } @@ -1464,7 +1463,7 @@ protected static T copyInstance( * Create a new {@link XContentParser}. */ protected final XContentParser createParser(XContentBuilder builder) throws IOException { - return createParser(builder.contentType().xContent(), BytesReferenceUtil.bytes(builder)); + return createParser(builder.contentType().xContent(), BytesReference.bytes(builder)); } /** diff --git a/test/framework/src/main/java/org/opensearch/test/RandomObjects.java b/test/framework/src/main/java/org/opensearch/test/RandomObjects.java index b4032190cdcd1..6405aa5ff5c95 100644 --- a/test/framework/src/main/java/org/opensearch/test/RandomObjects.java +++ b/test/framework/src/main/java/org/opensearch/test/RandomObjects.java @@ -47,7 +47,6 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -210,7 +209,7 @@ public static BytesReference randomSource(Random random, XContentType xContentTy builder.startObject(); addFields(random, builder, minNumFields, 0); builder.endObject(); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java b/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java index 7ebfeb629b3d1..3f8bfe8e9e935 100644 --- a/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java +++ b/test/framework/src/main/java/org/opensearch/test/XContentTestUtils.java @@ -33,7 +33,6 @@ package org.opensearch.test; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -72,13 +71,13 @@ public static Map convertToMap(ToXContent part) throws IOExcepti builder.startObject(); part.toXContent(builder, EMPTY_PARAMS); builder.endObject(); - return XContentHelper.convertToMap(BytesReferenceUtil.bytes(builder), false, builder.contentType()).v2(); + return XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); } public static BytesReference convertToXContent(Map map, XContentType xContentType) throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType)) { builder.map(map); - return BytesReferenceUtil.bytes(builder); + return BytesReference.bytes(builder); } } @@ -242,7 +241,7 @@ public static BytesReference insertRandomFields( } } }; - return BytesReferenceUtil.bytes( + return BytesReference.bytes( XContentTestUtils.insertIntoXContent( contentType.xContent(), xContent, diff --git a/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java b/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java index 0dbf8b2a12147..6cd03a3cf7256 100644 --- a/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java +++ b/test/framework/src/main/java/org/opensearch/test/rest/yaml/ClientYamlTestExecutionContext.java @@ -41,7 +41,7 @@ import org.apache.lucene.util.BytesRef; import org.opensearch.Version; import org.opensearch.client.NodeSelector; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -185,7 +185,7 @@ private XContentType getContentType(Map headers, XContentType[] private BytesRef bodyAsBytesRef(Map bodyAsMap, XContentType xContentType) throws IOException { Map finalBodyAsMap = stash.replaceStashedValues(bodyAsMap); try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType)) { - return BytesReferenceUtil.bytes(builder.map(finalBodyAsMap)).toBytesRef(); + return BytesReference.bytes(builder.map(finalBodyAsMap)).toBytesRef(); } } diff --git a/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java b/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java index a27e6b3ddb17b..494f7c906628f 100644 --- a/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java +++ b/test/framework/src/test/java/org/opensearch/test/AbstractXContentTestCaseTests.java @@ -35,7 +35,6 @@ import com.carrotsearch.randomizedtesting.RandomizedContext; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.xcontent.XContentParser; @@ -59,7 +58,7 @@ public void testInsertRandomFieldsAndShuffle() throws Exception { .runWithPrivateRandomness( 1, () -> AbstractXContentTestCase.insertRandomFieldsAndShuffle( - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), XContentType.JSON, true, new String[] {}, diff --git a/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java b/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java index f070f04557605..d430d7f2fbcb3 100644 --- a/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java +++ b/test/framework/src/test/java/org/opensearch/test/XContentTestUtilsTests.java @@ -32,7 +32,7 @@ package org.opensearch.test; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -90,7 +90,7 @@ public void testGetInsertPaths() throws IOException { XContentParser parser = XContentHelper.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), builder.contentType() ) ) { @@ -112,28 +112,28 @@ public void testInsertIntoXContent() throws IOException { builder.endObject(); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), Collections.singletonList(""), () -> "inn.er1", () -> new HashMap<>() ); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), Collections.singletonList(""), () -> "field1", () -> "value1" ); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), Collections.singletonList("inn\\.er1"), () -> "inner2", () -> new HashMap<>() ); builder = XContentTestUtils.insertIntoXContent( XContentType.JSON.xContent(), - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), Collections.singletonList("inn\\.er1"), () -> "field2", () -> "value2" @@ -142,7 +142,7 @@ public void testInsertIntoXContent() throws IOException { XContentParser parser = XContentHelper.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - BytesReferenceUtil.bytes(builder), + BytesReference.bytes(builder), builder.contentType() ) ) { @@ -195,7 +195,7 @@ public void testInsertRandomXContent() throws IOException { try ( XContentParser parser = createParser( XContentType.JSON.xContent(), - insertRandomFields(builder.contentType(), BytesReferenceUtil.bytes(builder), null, random()) + insertRandomFields(builder.contentType(), BytesReference.bytes(builder), null, random()) ) ) { resultMap = parser.map(); @@ -213,7 +213,7 @@ public void testInsertRandomXContent() throws IOException { try ( XContentParser parser = createParser( XContentType.JSON.xContent(), - insertRandomFields(builder.contentType(), BytesReferenceUtil.bytes(builder), pathsToExclude, random()) + insertRandomFields(builder.contentType(), BytesReference.bytes(builder), pathsToExclude, random()) ) ) { resultMap = parser.map(); @@ -231,7 +231,7 @@ public void testInsertRandomXContent() throws IOException { try ( XContentParser parser = createParser( XContentType.JSON.xContent(), - insertRandomFields(builder.contentType(), BytesReferenceUtil.bytes(builder), pathsToExclude, random()) + insertRandomFields(builder.contentType(), BytesReference.bytes(builder), pathsToExclude, random()) ) ) { resultMap = parser.map(); diff --git a/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java b/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java index c7adb1664388b..ba4ded7fcf604 100644 --- a/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java +++ b/test/framework/src/test/java/org/opensearch/test/hamcrest/OpenSearchAssertionsTests.java @@ -37,7 +37,7 @@ import org.opensearch.cluster.block.ClusterBlock; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -82,16 +82,12 @@ public void testAssertXContentEquivalent() throws IOException { try ( XContentBuilder copy = JsonXContent.contentBuilder(); - XContentParser parser = createParser(original.contentType().xContent(), BytesReferenceUtil.bytes(original)) + XContentParser parser = createParser(original.contentType().xContent(), BytesReference.bytes(original)) ) { parser.nextToken(); copy.generator().copyCurrentStructure(parser); try (XContentBuilder copyShuffled = shuffleXContent(copy)) { - assertToXContentEquivalent( - BytesReferenceUtil.bytes(original), - BytesReferenceUtil.bytes(copyShuffled), - original.contentType() - ); + assertToXContentEquivalent(BytesReference.bytes(original), BytesReference.bytes(copyShuffled), original.contentType()); } } } @@ -123,11 +119,7 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent( - BytesReferenceUtil.bytes(builder), - BytesReferenceUtil.bytes(otherBuilder), - builder.contentType() - ) + () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) ); assertThat(error.getMessage(), containsString("f2: expected [value2] but not found")); } @@ -157,11 +149,7 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent( - BytesReferenceUtil.bytes(builder), - BytesReferenceUtil.bytes(otherBuilder), - builder.contentType() - ) + () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) ); assertThat(error.getMessage(), containsString("f2: expected String [value2] but was String [differentValue2]")); } @@ -195,11 +183,7 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent( - BytesReferenceUtil.bytes(builder), - BytesReferenceUtil.bytes(otherBuilder), - builder.contentType() - ) + () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) ); assertThat(error.getMessage(), containsString("2: expected String [three] but was String [four]")); } @@ -230,11 +214,7 @@ public void testAssertXContentEquivalentErrors() throws IOException { otherBuilder.endObject(); AssertionError error = expectThrows( AssertionError.class, - () -> assertToXContentEquivalent( - BytesReferenceUtil.bytes(builder), - BytesReferenceUtil.bytes(otherBuilder), - builder.contentType() - ) + () -> assertToXContentEquivalent(BytesReference.bytes(builder), BytesReference.bytes(otherBuilder), builder.contentType()) ); assertThat(error.getMessage(), containsString("expected [1] more entries")); } diff --git a/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java b/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java index 773d2f8e7ab8a..2465e48b9afac 100644 --- a/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java +++ b/test/framework/src/test/java/org/opensearch/test/rest/yaml/ObjectPathTests.java @@ -31,7 +31,7 @@ package org.opensearch.test.rest.yaml; -import org.opensearch.common.util.BytesReferenceUtil; +import org.opensearch.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -68,7 +68,7 @@ public void testEvaluateObjectPathEscape() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.field2\\.field3"); assertThat(object, instanceOf(String.class)); @@ -84,7 +84,7 @@ public void testEvaluateObjectPathWithDots() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1..field2"); assertThat(object, instanceOf(String.class)); @@ -106,7 +106,7 @@ public void testEvaluateInteger() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.field2"); assertThat(object, instanceOf(Integer.class)); @@ -122,7 +122,7 @@ public void testEvaluateDouble() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.field2"); assertThat(object, instanceOf(Double.class)); @@ -138,7 +138,7 @@ public void testEvaluateArray() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.array1"); assertThat(object, instanceOf(List.class)); @@ -170,7 +170,7 @@ public void testEvaluateArrayElementObject() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("field1.array1.1.element"); assertThat(object, instanceOf(String.class)); @@ -200,7 +200,7 @@ public void testEvaluateObjectKeys() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate("metadata.templates"); assertThat(object, instanceOf(Map.class)); @@ -232,7 +232,7 @@ public void testEvaluateArbitraryKey() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); { @@ -277,7 +277,7 @@ public void testEvaluateStashInPropertyName() throws Exception { xContentBuilder.endObject(); ObjectPath objectPath = ObjectPath.createFromXContent( xContentBuilder.contentType().xContent(), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); try { objectPath.evaluate("field1.$placeholder.element1"); @@ -343,7 +343,7 @@ public void testEvaluateArrayAsRoot() throws Exception { xContentBuilder.endArray(); ObjectPath objectPath = ObjectPath.createFromXContent( XContentFactory.xContent(xContentBuilder.contentType()), - BytesReferenceUtil.bytes(xContentBuilder) + BytesReference.bytes(xContentBuilder) ); Object object = objectPath.evaluate(""); assertThat(object, notNullValue()); diff --git a/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java b/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java index 18514243aa106..ff862a5ae673e 100644 --- a/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java +++ b/test/framework/src/test/java/org/opensearch/test/test/OpenSearchTestCaseTests.java @@ -36,7 +36,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.time.DateFormatter; -import org.opensearch.common.util.BytesReferenceUtil; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; @@ -133,7 +132,7 @@ public void testShuffleXContentExcludeFields() throws IOException { } } builder.endObject(); - BytesReference bytes = BytesReferenceUtil.bytes(builder); + BytesReference bytes = BytesReference.bytes(builder); final LinkedHashMap initialMap; try (XContentParser parser = createParser(xContentType.xContent(), bytes)) { initialMap = (LinkedHashMap) parser.mapOrdered(); From 1c8d50caf7f7a9ac1d64adaa997eb9451050a116 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 14 Jun 2023 11:14:38 -0500 Subject: [PATCH 5/8] simplify OpenSearchServerException registration Signed-off-by: Nicholas Walter Knize --- .../opensearch/OpenSearchServerException.java | 294 +++++++++--------- 1 file changed, 145 insertions(+), 149 deletions(-) diff --git a/server/src/main/java/org/opensearch/OpenSearchServerException.java b/server/src/main/java/org/opensearch/OpenSearchServerException.java index dff17ef33aefe..825197c07b977 100644 --- a/server/src/main/java/org/opensearch/OpenSearchServerException.java +++ b/server/src/main/java/org/opensearch/OpenSearchServerException.java @@ -10,6 +10,7 @@ import org.opensearch.index.snapshots.IndexShardSnapshotException; +import static org.opensearch.OpenSearchException.OpenSearchExceptionHandle; import static org.opensearch.OpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; import static org.opensearch.OpenSearchException.UNKNOWN_VERSION_ADDED; import static org.opensearch.Version.V_2_1_0; @@ -37,7 +38,7 @@ private OpenSearchServerException() { public static void registerExceptions() { registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.dfs.DfsPhaseExecutionException.class, org.opensearch.search.dfs.DfsPhaseExecutionException::new, 1, @@ -45,7 +46,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.util.CancellableThreads.ExecutionCancelledException.class, org.opensearch.common.util.CancellableThreads.ExecutionCancelledException::new, 2, @@ -53,7 +54,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.discovery.ClusterManagerNotDiscoveredException.class, org.opensearch.discovery.ClusterManagerNotDiscoveredException::new, 3, @@ -61,7 +62,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.OpenSearchSecurityException.class, org.opensearch.OpenSearchSecurityException::new, 4, @@ -69,7 +70,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardRestoreException.class, org.opensearch.index.snapshots.IndexShardRestoreException::new, 5, @@ -77,7 +78,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.IndexClosedException.class, org.opensearch.indices.IndexClosedException::new, 6, @@ -85,7 +86,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.http.BindHttpException.class, org.opensearch.http.BindHttpException::new, 7, @@ -93,7 +94,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.search.ReduceSearchPhaseException.class, org.opensearch.action.search.ReduceSearchPhaseException::new, 8, @@ -101,7 +102,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.node.NodeClosedException.class, org.opensearch.node.NodeClosedException::new, 9, @@ -109,7 +110,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.SnapshotFailedEngineException.class, org.opensearch.index.engine.SnapshotFailedEngineException::new, 10, @@ -117,7 +118,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.ShardNotFoundException.class, org.opensearch.index.shard.ShardNotFoundException::new, 11, @@ -125,7 +126,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.ConnectTransportException.class, org.opensearch.transport.ConnectTransportException::new, 12, @@ -133,7 +134,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.NotSerializableTransportException.class, org.opensearch.transport.NotSerializableTransportException::new, 13, @@ -141,7 +142,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.ResponseHandlerFailureTransportException.class, org.opensearch.transport.ResponseHandlerFailureTransportException::new, 14, @@ -149,7 +150,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.IndexCreationException.class, org.opensearch.indices.IndexCreationException::new, 15, @@ -157,7 +158,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.IndexNotFoundException.class, org.opensearch.index.IndexNotFoundException::new, 16, @@ -165,7 +166,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.routing.IllegalShardRoutingStateException.class, org.opensearch.cluster.routing.IllegalShardRoutingStateException::new, 17, @@ -173,7 +174,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException.class, org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException::new, 18, @@ -181,7 +182,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.ResourceNotFoundException.class, org.opensearch.ResourceNotFoundException::new, 19, @@ -189,7 +190,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.ActionTransportException.class, org.opensearch.transport.ActionTransportException::new, 20, @@ -197,7 +198,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.OpenSearchGenerationException.class, org.opensearch.OpenSearchGenerationException::new, 21, @@ -206,7 +207,7 @@ public static void registerExceptions() { ); // 22 was CreateFailedEngineException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardStartedException.class, org.opensearch.index.shard.IndexShardStartedException::new, 23, @@ -214,7 +215,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.SearchContextMissingException.class, org.opensearch.search.SearchContextMissingException::new, 24, @@ -222,7 +223,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.script.GeneralScriptException.class, org.opensearch.script.GeneralScriptException::new, 25, @@ -231,7 +232,7 @@ public static void registerExceptions() { ); // 26 was BatchOperationException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotCreationException.class, org.opensearch.snapshots.SnapshotCreationException::new, 27, @@ -240,7 +241,7 @@ public static void registerExceptions() { ); // 28 was DeleteFailedEngineException, deprecated in 6.0, removed in 7.0 registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.DocumentMissingException.class, org.opensearch.index.engine.DocumentMissingException::new, 29, @@ -248,7 +249,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotException.class, org.opensearch.snapshots.SnapshotException::new, 30, @@ -256,7 +257,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.InvalidAliasNameException.class, org.opensearch.indices.InvalidAliasNameException::new, 31, @@ -264,7 +265,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.InvalidIndexNameException.class, org.opensearch.indices.InvalidIndexNameException::new, 32, @@ -272,7 +273,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.IndexPrimaryShardNotAllocatedException.class, org.opensearch.indices.IndexPrimaryShardNotAllocatedException::new, 33, @@ -280,7 +281,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.TransportException.class, org.opensearch.transport.TransportException::new, 34, @@ -288,7 +289,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.OpenSearchParseException.class, org.opensearch.OpenSearchParseException::new, 35, @@ -296,7 +297,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.SearchException.class, org.opensearch.search.SearchException::new, 36, @@ -304,7 +305,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.mapper.MapperException.class, org.opensearch.index.mapper.MapperException::new, 37, @@ -312,7 +313,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.InvalidTypeNameException.class, org.opensearch.indices.InvalidTypeNameException::new, 38, @@ -320,7 +321,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotRestoreException.class, org.opensearch.snapshots.SnapshotRestoreException::new, 39, @@ -328,7 +329,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardClosedException.class, org.opensearch.index.shard.IndexShardClosedException::new, 41, @@ -336,7 +337,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.recovery.RecoverFilesRecoveryException.class, org.opensearch.indices.recovery.RecoverFilesRecoveryException::new, 42, @@ -344,7 +345,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.translog.TruncatedTranslogException.class, org.opensearch.index.translog.TruncatedTranslogException::new, 43, @@ -352,7 +353,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.recovery.RecoveryFailedException.class, org.opensearch.indices.recovery.RecoveryFailedException::new, 44, @@ -360,7 +361,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRelocatedException.class, org.opensearch.index.shard.IndexShardRelocatedException::new, 45, @@ -368,7 +369,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.NodeShouldNotConnectException.class, org.opensearch.transport.NodeShouldNotConnectException::new, 46, @@ -377,7 +378,7 @@ public static void registerExceptions() { ); // 47 used to be for IndexTemplateAlreadyExistsException which was deprecated in 5.1 removed in 6.0 registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.translog.TranslogCorruptedException.class, org.opensearch.index.translog.TranslogCorruptedException::new, 48, @@ -385,7 +386,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.block.ClusterBlockException.class, org.opensearch.cluster.block.ClusterBlockException::new, 49, @@ -393,7 +394,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.fetch.FetchPhaseExecutionException.class, org.opensearch.search.fetch.FetchPhaseExecutionException::new, 50, @@ -402,7 +403,7 @@ public static void registerExceptions() { ); // 51 used to be for IndexShardAlreadyExistsException which was deprecated in 5.1 removed in 6.0 registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.VersionConflictEngineException.class, org.opensearch.index.engine.VersionConflictEngineException::new, 52, @@ -410,7 +411,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.EngineException.class, org.opensearch.index.engine.EngineException::new, 53, @@ -419,7 +420,7 @@ public static void registerExceptions() { ); // 54 was DocumentAlreadyExistsException, which is superseded by VersionConflictEngineException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.NoSuchNodeException.class, org.opensearch.action.NoSuchNodeException::new, 55, @@ -427,7 +428,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.settings.SettingsException.class, org.opensearch.common.settings.SettingsException::new, 56, @@ -435,7 +436,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.IndexTemplateMissingException.class, org.opensearch.indices.IndexTemplateMissingException::new, 57, @@ -443,7 +444,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.SendRequestTransportException.class, org.opensearch.transport.SendRequestTransportException::new, 58, @@ -454,7 +455,7 @@ public static void registerExceptions() { // 60 used to be for EarlyTerminationException // 61 used to be for RoutingValidationException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.AliasFilterParsingException.class, org.opensearch.indices.AliasFilterParsingException::new, 63, @@ -463,7 +464,7 @@ public static void registerExceptions() { ); // 64 was DeleteByQueryFailedEngineException, which was removed in 5.0 registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.gateway.GatewayException.class, org.opensearch.gateway.GatewayException::new, 65, @@ -471,7 +472,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardNotRecoveringException.class, org.opensearch.index.shard.IndexShardNotRecoveringException::new, 66, @@ -479,7 +480,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.http.HttpException.class, org.opensearch.http.HttpException::new, 67, @@ -487,7 +488,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.OpenSearchException.class, org.opensearch.OpenSearchException::new, 68, @@ -495,7 +496,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotMissingException.class, org.opensearch.snapshots.SnapshotMissingException::new, 69, @@ -503,7 +504,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.PrimaryMissingActionException.class, org.opensearch.action.PrimaryMissingActionException::new, 70, @@ -511,7 +512,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.SearchParseException.class, org.opensearch.search.SearchParseException::new, 72, @@ -519,7 +520,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.FailedNodeException.class, org.opensearch.action.FailedNodeException::new, 71, @@ -527,7 +528,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.ConcurrentSnapshotExecutionException.class, org.opensearch.snapshots.ConcurrentSnapshotExecutionException::new, 73, @@ -535,7 +536,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.blobstore.BlobStoreException.class, org.opensearch.common.blobstore.BlobStoreException::new, 74, @@ -543,7 +544,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.IncompatibleClusterStateVersionException.class, org.opensearch.cluster.IncompatibleClusterStateVersionException::new, 75, @@ -551,7 +552,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.RecoveryEngineException.class, org.opensearch.index.engine.RecoveryEngineException::new, 76, @@ -559,7 +560,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.util.concurrent.UncategorizedExecutionException.class, org.opensearch.common.util.concurrent.UncategorizedExecutionException::new, 77, @@ -567,7 +568,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.TimestampParsingException.class, org.opensearch.action.TimestampParsingException::new, 78, @@ -575,7 +576,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.RoutingMissingException.class, org.opensearch.action.RoutingMissingException::new, 79, @@ -584,7 +585,7 @@ public static void registerExceptions() { ); // 80 was IndexFailedEngineException, deprecated in 6.0, removed in 7.0 registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.snapshots.IndexShardRestoreFailedException.class, org.opensearch.index.snapshots.IndexShardRestoreFailedException::new, 81, @@ -592,7 +593,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.repositories.RepositoryException.class, org.opensearch.repositories.RepositoryException::new, 82, @@ -600,7 +601,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.ReceiveTimeoutTransportException.class, org.opensearch.transport.ReceiveTimeoutTransportException::new, 83, @@ -608,7 +609,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.NodeDisconnectedException.class, org.opensearch.transport.NodeDisconnectedException::new, 84, @@ -617,7 +618,7 @@ public static void registerExceptions() { ); // 85 used to be for AlreadyExpiredException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.aggregations.AggregationExecutionException.class, org.opensearch.search.aggregations.AggregationExecutionException::new, 86, @@ -626,7 +627,7 @@ public static void registerExceptions() { ); // 87 used to be for MergeMappingException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.InvalidIndexTemplateException.class, org.opensearch.indices.InvalidIndexTemplateException::new, 88, @@ -634,7 +635,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.RefreshFailedEngineException.class, org.opensearch.index.engine.RefreshFailedEngineException::new, 90, @@ -642,7 +643,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.aggregations.AggregationInitializationException.class, org.opensearch.search.aggregations.AggregationInitializationException::new, 91, @@ -650,7 +651,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.recovery.DelayRecoveryException.class, org.opensearch.indices.recovery.DelayRecoveryException::new, 92, @@ -659,7 +660,7 @@ public static void registerExceptions() { ); // 93 used to be for IndexWarmerMissingException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.client.transport.NoNodeAvailableException.class, org.opensearch.client.transport.NoNodeAvailableException::new, 94, @@ -667,7 +668,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.InvalidSnapshotNameException.class, org.opensearch.snapshots.InvalidSnapshotNameException::new, 96, @@ -675,7 +676,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IllegalIndexShardStateException.class, org.opensearch.index.shard.IllegalIndexShardStateException::new, 97, @@ -683,15 +684,10 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( - IndexShardSnapshotException.class, - IndexShardSnapshotException::new, - 98, - UNKNOWN_VERSION_ADDED - ) + new OpenSearchExceptionHandle(IndexShardSnapshotException.class, IndexShardSnapshotException::new, 98, UNKNOWN_VERSION_ADDED) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardNotStartedException.class, org.opensearch.index.shard.IndexShardNotStartedException::new, 99, @@ -699,7 +695,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.search.SearchPhaseExecutionException.class, org.opensearch.action.search.SearchPhaseExecutionException::new, 100, @@ -707,7 +703,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.ActionNotFoundTransportException.class, org.opensearch.transport.ActionNotFoundTransportException::new, 101, @@ -715,7 +711,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.TransportSerializationException.class, org.opensearch.transport.TransportSerializationException::new, 102, @@ -723,7 +719,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.RemoteTransportException.class, org.opensearch.transport.RemoteTransportException::new, 103, @@ -731,7 +727,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.EngineCreationFailureException.class, org.opensearch.index.engine.EngineCreationFailureException::new, 104, @@ -739,7 +735,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.routing.RoutingException.class, org.opensearch.cluster.routing.RoutingException::new, 105, @@ -747,7 +743,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRecoveryException.class, org.opensearch.index.shard.IndexShardRecoveryException::new, 106, @@ -755,7 +751,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.repositories.RepositoryMissingException.class, org.opensearch.repositories.RepositoryMissingException::new, 107, @@ -763,7 +759,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.DocumentSourceMissingException.class, org.opensearch.index.engine.DocumentSourceMissingException::new, 109, @@ -772,7 +768,7 @@ public static void registerExceptions() { ); // 110 used to be FlushNotAllowedEngineException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.settings.NoClassSettingsException.class, org.opensearch.common.settings.NoClassSettingsException::new, 111, @@ -780,7 +776,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.BindTransportException.class, org.opensearch.transport.BindTransportException::new, 112, @@ -788,7 +784,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.rest.action.admin.indices.AliasesNotFoundException.class, org.opensearch.rest.action.admin.indices.AliasesNotFoundException::new, 113, @@ -796,7 +792,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.IndexShardRecoveringException.class, org.opensearch.index.shard.IndexShardRecoveringException::new, 114, @@ -804,7 +800,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.translog.TranslogException.class, org.opensearch.index.translog.TranslogException::new, 115, @@ -812,7 +808,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException.class, org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException::new, 116, @@ -820,7 +816,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.support.replication.ReplicationOperation.RetryOnPrimaryException.class, org.opensearch.action.support.replication.ReplicationOperation.RetryOnPrimaryException::new, 117, @@ -828,7 +824,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.OpenSearchTimeoutException.class, org.opensearch.OpenSearchTimeoutException::new, 118, @@ -836,7 +832,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.query.QueryPhaseExecutionException.class, org.opensearch.search.query.QueryPhaseExecutionException::new, 119, @@ -844,7 +840,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.repositories.RepositoryVerificationException.class, org.opensearch.repositories.RepositoryVerificationException::new, 120, @@ -852,7 +848,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.aggregations.InvalidAggregationPathException.class, org.opensearch.search.aggregations.InvalidAggregationPathException::new, 121, @@ -861,7 +857,7 @@ public static void registerExceptions() { ); // 123 used to be IndexAlreadyExistsException and was renamed registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( ResourceAlreadyExistsException.class, ResourceAlreadyExistsException::new, 123, @@ -870,7 +866,7 @@ public static void registerExceptions() { ); // 124 used to be Script.ScriptParseException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.TcpTransport.HttpRequestOnTransportException.class, org.opensearch.transport.TcpTransport.HttpRequestOnTransportException::new, 125, @@ -878,7 +874,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.mapper.MapperParsingException.class, org.opensearch.index.mapper.MapperParsingException::new, 126, @@ -887,7 +883,7 @@ public static void registerExceptions() { ); // 127 used to be org.opensearch.search.SearchContextException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.builder.SearchSourceBuilderException.class, org.opensearch.search.builder.SearchSourceBuilderException::new, 128, @@ -896,7 +892,7 @@ public static void registerExceptions() { ); // 129 was EngineClosedException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.NoShardAvailableActionException.class, org.opensearch.action.NoShardAvailableActionException::new, 130, @@ -904,7 +900,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.UnavailableShardsException.class, org.opensearch.action.UnavailableShardsException::new, 131, @@ -912,7 +908,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.engine.FlushFailedEngineException.class, org.opensearch.index.engine.FlushFailedEngineException::new, 132, @@ -920,7 +916,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.common.breaker.CircuitBreakingException.class, org.opensearch.common.breaker.CircuitBreakingException::new, 133, @@ -928,7 +924,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.NodeNotConnectedException.class, org.opensearch.transport.NodeNotConnectedException::new, 134, @@ -936,7 +932,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.mapper.StrictDynamicMappingException.class, org.opensearch.index.mapper.StrictDynamicMappingException::new, 135, @@ -944,7 +940,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException.class, org.opensearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException::new, 136, @@ -952,7 +948,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.TypeMissingException.class, org.opensearch.indices.TypeMissingException::new, 137, @@ -960,7 +956,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.coordination.FailedToCommitClusterStateException.class, org.opensearch.cluster.coordination.FailedToCommitClusterStateException::new, 140, @@ -968,7 +964,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.query.QueryShardException.class, org.opensearch.index.query.QueryShardException::new, 141, @@ -976,7 +972,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.action.shard.ShardStateAction.NoLongerPrimaryShardException.class, org.opensearch.cluster.action.shard.ShardStateAction.NoLongerPrimaryShardException::new, 142, @@ -984,7 +980,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.script.ScriptException.class, org.opensearch.script.ScriptException::new, 143, @@ -992,7 +988,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.NotClusterManagerException.class, org.opensearch.cluster.NotClusterManagerException::new, 144, @@ -1000,7 +996,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.OpenSearchStatusException.class, org.opensearch.OpenSearchStatusException::new, 145, @@ -1008,7 +1004,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.tasks.TaskCancelledException.class, org.opensearch.tasks.TaskCancelledException::new, 146, @@ -1016,7 +1012,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.env.ShardLockObtainFailedException.class, org.opensearch.env.ShardLockObtainFailedException::new, 147, @@ -1025,7 +1021,7 @@ public static void registerExceptions() { ); // 148 was UnknownNamedObjectException registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.aggregations.MultiBucketConsumerService.TooManyBucketsException.class, org.opensearch.search.aggregations.MultiBucketConsumerService.TooManyBucketsException::new, 149, @@ -1033,7 +1029,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.coordination.CoordinationStateRejectedException.class, org.opensearch.cluster.coordination.CoordinationStateRejectedException::new, 150, @@ -1041,7 +1037,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotInProgressException.class, org.opensearch.snapshots.SnapshotInProgressException::new, 151, @@ -1049,7 +1045,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.NoSuchRemoteClusterException.class, org.opensearch.transport.NoSuchRemoteClusterException::new, 152, @@ -1057,7 +1053,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException.class, org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException::new, 153, @@ -1065,7 +1061,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseNotFoundException.class, org.opensearch.index.seqno.RetentionLeaseNotFoundException::new, 154, @@ -1073,7 +1069,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.ShardNotInPrimaryModeException.class, org.opensearch.index.shard.ShardNotInPrimaryModeException::new, 155, @@ -1081,7 +1077,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException.class, org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException::new, 156, @@ -1089,7 +1085,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.ingest.IngestProcessorException.class, org.opensearch.ingest.IngestProcessorException::new, 157, @@ -1097,7 +1093,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.recovery.PeerRecoveryNotFound.class, org.opensearch.indices.recovery.PeerRecoveryNotFound::new, 158, @@ -1105,7 +1101,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.coordination.NodeHealthCheckFailureException.class, org.opensearch.cluster.coordination.NodeHealthCheckFailureException::new, 159, @@ -1113,7 +1109,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.transport.NoSeedNodeLeftException.class, org.opensearch.transport.NoSeedNodeLeftException::new, 160, @@ -1121,7 +1117,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.indices.replication.common.ReplicationFailedException.class, org.opensearch.indices.replication.common.ReplicationFailedException::new, 161, @@ -1129,7 +1125,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.index.shard.PrimaryShardClosedException.class, org.opensearch.index.shard.PrimaryShardClosedException::new, 162, @@ -1137,7 +1133,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.decommission.DecommissioningFailedException.class, org.opensearch.cluster.decommission.DecommissioningFailedException::new, 163, @@ -1145,7 +1141,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.decommission.NodeDecommissionedException.class, org.opensearch.cluster.decommission.NodeDecommissionedException::new, 164, @@ -1153,7 +1149,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.service.ClusterManagerThrottlingException.class, org.opensearch.cluster.service.ClusterManagerThrottlingException::new, 165, @@ -1161,7 +1157,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.snapshots.SnapshotInUseDeletionException.class, org.opensearch.snapshots.SnapshotInUseDeletionException::new, 166, @@ -1169,7 +1165,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException.class, org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException::new, 167, @@ -1177,7 +1173,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException.class, org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException::new, 168, @@ -1185,7 +1181,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.routing.NodeWeighedAwayException.class, org.opensearch.cluster.routing.NodeWeighedAwayException::new, 169, @@ -1193,7 +1189,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.search.pipeline.SearchPipelineProcessingException.class, org.opensearch.search.pipeline.SearchPipelineProcessingException::new, 170, @@ -1201,7 +1197,7 @@ public static void registerExceptions() { ) ); registerExceptionHandle( - new OpenSearchException.OpenSearchExceptionHandle( + new OpenSearchExceptionHandle( org.opensearch.cluster.block.IndexCreateBlockException.class, org.opensearch.cluster.block.IndexCreateBlockException::new, CUSTOM_ELASTICSEARCH_EXCEPTIONS_BASE_ID + 1, From 2cd0ad8e9ce15ac4f53ef31b0b731c0d11163e7d Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Fri, 16 Jun 2023 11:33:31 -0500 Subject: [PATCH 6/8] Refactor ExceptionsHelper to opensearch-core and remove BaseExceptionsHelper Signed-off-by: Nicholas Walter Knize --- .../org/opensearch/BaseExceptionsHelper.java | 311 ------ .../java/org/opensearch/ExceptionsHelper.java | 104 +- .../org/opensearch/OpenSearchException.java | 926 ++++++++++-------- .../DefaultShardOperationFailedException.java | 8 +- .../NotSerializableExceptionWrapper.java | 8 +- .../geogrid/GeoTileGridParserTests.java | 4 +- .../reindex/AsyncBulkByScrollActionTests.java | 3 +- .../opensearch/action/RejectionActionIT.java | 4 +- .../action/search/TransportSearchIT.java | 8 +- .../org/opensearch/blocks/SimpleBlocksIT.java | 6 +- .../breaker/CircuitBreakerServiceIT.java | 4 +- .../indices/state/CloseIndexIT.java | 4 +- .../aggregations/pipeline/DerivativeIT.java | 4 +- .../pipeline/ExtendedStatsBucketIT.java | 4 +- .../pipeline/PercentilesBucketIT.java | 6 +- .../SharedClusterSnapshotRestoreIT.java | 4 +- .../OpenSearchSecurityException.java | 2 +- .../action/TaskOperationFailure.java | 6 +- .../NodesReloadSecureSettingsResponse.java | 4 +- .../shards/IndicesShardStoresResponse.java | 4 +- .../action/bulk/BulkItemResponse.java | 14 +- .../action/bulk/TransportBulkAction.java | 4 +- .../action/bulk/TransportShardBulkAction.java | 4 +- .../action/search/MultiSearchResponse.java | 4 +- .../search/SearchPhaseExecutionException.java | 9 +- .../action/search/ShardSearchFailure.java | 12 +- .../action/support/TransportActions.java | 4 +- .../replication/ReplicationOperation.java | 8 +- .../replication/ReplicationResponse.java | 6 +- .../TransportBroadcastReplicationAction.java | 4 +- .../action/shard/ShardStateAction.java | 3 +- .../cluster/routing/UnassignedInfo.java | 4 +- .../routing/allocation/FailedShard.java | 4 +- .../allocation/NodeAllocationResult.java | 4 +- .../java/org/opensearch/common/Strings.java | 4 +- .../common/lucene/search/Queries.java | 4 +- .../opensearch/gateway/AsyncShardFetch.java | 4 +- .../index/engine/InternalEngine.java | 6 +- .../index/mapper/MappedFieldType.java | 6 +- .../index/query/MoreLikeThisQueryBuilder.java | 3 +- .../index/reindex/BulkByScrollTask.java | 3 +- .../index/reindex/ScrollableHitSource.java | 9 +- .../opensearch/index/shard/IndexShard.java | 3 +- .../opensearch/index/shard/StoreRecovery.java | 4 +- .../recovery/PeerRecoveryTargetService.java | 6 +- .../recovery/RetryableTransportClient.java | 6 +- .../SegmentReplicationTargetService.java | 4 +- .../replication/common/ReplicationTarget.java | 4 +- .../opensearch/rest/BytesRestResponse.java | 15 +- .../DirectCandidateGeneratorBuilder.java | 4 +- .../tasks/TaskCancellationService.java | 6 +- .../org/opensearch/tasks/TaskManager.java | 5 +- .../java/org/opensearch/tasks/TaskResult.java | 4 +- .../opensearch/tasks/TaskResultsService.java | 4 +- .../org/opensearch/ExceptionsHelperTests.java | 15 +- .../opensearch/OpenSearchExceptionTests.java | 24 +- .../action/bulk/BulkItemResponseTests.java | 4 +- .../action/bulk/BulkResponseTests.java | 4 +- .../client/AbstractClientHeadersTestCase.java | 4 +- .../rest/BytesRestResponseTests.java | 4 +- .../pipeline/DerivativeAggregatorTests.java | 4 +- .../transport/TransportActionProxyTests.java | 4 +- .../test/OpenSearchIntegTestCase.java | 4 +- .../test/hamcrest/OpenSearchAssertions.java | 5 +- .../AbstractSimpleTransportTestCase.java | 11 +- 65 files changed, 791 insertions(+), 904 deletions(-) delete mode 100644 libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java rename {server => libs/core}/src/main/java/org/opensearch/ExceptionsHelper.java (76%) diff --git a/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java b/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java deleted file mode 100644 index 129ff99e65458..0000000000000 --- a/libs/core/src/main/java/org/opensearch/BaseExceptionsHelper.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ -package org.opensearch; - -import com.fasterxml.jackson.core.JsonParseException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.common.compress.NotXContentException; -import org.opensearch.core.ParseField; -import org.opensearch.core.common.Strings; -import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; -import org.opensearch.core.xcontent.ToXContent; -import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.rest.RestStatus; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.List; -import java.util.Map; - -import static java.util.Collections.emptyMap; - -/** - * Base helper class for OpenSearch Exceptions - * - * @opensearch.internal - */ -public abstract class BaseExceptionsHelper { - /** - * Passed in the {@link ToXContent.Params} of {@link #generateThrowableXContent(XContentBuilder, ToXContent.Params, Throwable)} - * to control if the {@code stack_trace} element should render. Unlike most parameters to {@code toXContent} methods this parameter is - * internal only and not available as a URL parameter. Use the {@code error_trace} parameter instead. - */ - public static final String REST_EXCEPTION_SKIP_STACK_TRACE = "rest.exception.stacktrace.skip"; - public static final boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT = true; - public static final String STACK_TRACE = "stack_trace"; - protected static final Logger logger = LogManager.getLogger(BaseExceptionsHelper.class); - protected static final String OPENSEARCH_PREFIX_KEY = "opensearch."; - /** - * Passed in the {@link ToXContent.Params} of {@link #generateThrowableXContent(XContentBuilder, ToXContent.Params, Throwable)} - * to control if the {@code caused_by} element should render. Unlike most parameters to {@code toXContent} methods this parameter is - * internal only and not available as a URL parameter. - */ - protected static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.cause.skip"; - protected static final String TYPE = "type"; - protected static final String REASON = "reason"; - protected static final String CAUSED_BY = "caused_by"; - protected static final ParseField SUPPRESSED = new ParseField("suppressed"); - protected static final String HEADER = "header"; - private static final boolean REST_EXCEPTION_SKIP_CAUSE_DEFAULT = false; - - public static Throwable unwrapCause(Throwable t) { - int counter = 0; - Throwable result = t; - while (result instanceof OpenSearchWrapperException) { - if (result.getCause() == null) { - return result; - } - if (result.getCause() == result) { - return result; - } - if (counter++ > 10) { - // dear god, if we got more than 10 levels down, WTF? just bail - logger.warn("Exception cause unwrapping ran for 10 levels...", t); - return result; - } - result = result.getCause(); - } - return result; - } - - /** - * @deprecated Don't swallow exceptions, allow them to propagate. - */ - @Deprecated - public static String detailedMessage(Throwable t) { - if (t == null) { - return "Unknown"; - } - if (t.getCause() != null) { - StringBuilder sb = new StringBuilder(); - while (t != null) { - sb.append(getExceptionSimpleClassName(t)); - if (t.getMessage() != null) { - sb.append("["); - sb.append(t.getMessage()); - sb.append("]"); - } - sb.append("; "); - t = t.getCause(); - if (t != null) { - sb.append("nested: "); - } - } - return sb.toString(); - } else { - return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; - } - } - - public static String stackTrace(Throwable e) { - StringWriter stackTraceStringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stackTraceStringWriter); - e.printStackTrace(printWriter); - return stackTraceStringWriter.toString(); - } - - public static String summaryMessage(Throwable t) { - if (t != null) { - if (t instanceof OpenSearchException) { - return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; - } else if (t instanceof IllegalArgumentException) { - return "Invalid argument"; - } else if (t instanceof JsonParseException) { - return "Failed to parse JSON"; - } else if (t instanceof OpenSearchRejectedExecutionException) { - return "Too many requests"; - } - } - return "Internal failure"; - } - - public static void innerToXContent( - XContentBuilder builder, - ToXContent.Params params, - Throwable throwable, - String type, - String message, - Map> headers, - Map> metadata, - Throwable cause - ) throws IOException { - builder.field(TYPE, type); - builder.field(REASON, message); - - for (Map.Entry> entry : metadata.entrySet()) { - headerToXContent(builder, entry.getKey().substring(OPENSEARCH_PREFIX_KEY.length()), entry.getValue()); - } - - if (throwable instanceof OpenSearchException) { - OpenSearchException exception = (OpenSearchException) throwable; - exception.metadataToXContent(builder, params); - } - - if (params.paramAsBoolean(REST_EXCEPTION_SKIP_CAUSE, REST_EXCEPTION_SKIP_CAUSE_DEFAULT) == false) { - if (cause != null) { - builder.field(CAUSED_BY); - builder.startObject(); - generateThrowableXContent(builder, params, cause); - builder.endObject(); - } - } - - if (headers.isEmpty() == false) { - builder.startObject(HEADER); - for (Map.Entry> entry : headers.entrySet()) { - headerToXContent(builder, entry.getKey(), entry.getValue()); - } - builder.endObject(); - } - - if (params.paramAsBoolean(REST_EXCEPTION_SKIP_STACK_TRACE, REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT) == false) { - builder.field(STACK_TRACE, stackTrace(throwable)); - } - - Throwable[] allSuppressed = throwable.getSuppressed(); - if (allSuppressed.length > 0) { - builder.startArray(SUPPRESSED.getPreferredName()); - for (Throwable suppressed : allSuppressed) { - builder.startObject(); - generateThrowableXContent(builder, params, suppressed); - builder.endObject(); - } - builder.endArray(); - } - } - - /** - * Static toXContent helper method that renders {@link OpenSearchException} or {@link Throwable} instances - * as XContent, delegating the rendering to {@link OpenSearchException#toXContent(XContentBuilder, ToXContent.Params)} - * or {@link #innerToXContent(XContentBuilder, ToXContent.Params, Throwable, String, String, Map, Map, Throwable)}. - * - * This method is usually used when the {@link Throwable} is rendered as a part of another XContent object, and its result can - * be parsed back using the {@code OpenSearchException.fromXContent(XContentParser)} method. - */ - public static void generateThrowableXContent(XContentBuilder builder, ToXContent.Params params, Throwable t) throws IOException { - t = unwrapCause(t); - - if (t instanceof OpenSearchException) { - ((OpenSearchException) t).toXContent(builder, params); - } else { - innerToXContent(builder, params, t, getExceptionName(t), t.getMessage(), emptyMap(), emptyMap(), t.getCause()); - } - } - - /** - * Returns an underscore case name for the given exception. This method strips {@code OpenSearch} prefixes from exception names. - */ - public static String getExceptionName(Throwable ex) { - String simpleName = getExceptionSimpleClassName(ex); - if (simpleName.startsWith("OpenSearch")) { - simpleName = simpleName.substring("OpenSearch".length()); - } - // TODO: do we really need to make the exception name in underscore casing? - return toUnderscoreCase(simpleName); - } - - private static String getExceptionSimpleClassName(final Throwable ex) { - String simpleName = ex.getClass().getSimpleName(); - if (Strings.isEmpty(simpleName)) { - simpleName = "OpenSearchException"; - } - return simpleName; - } - - // lower cases and adds underscores to transitions in a name - private static String toUnderscoreCase(String value) { - StringBuilder sb = new StringBuilder(); - boolean changed = false; - for (int i = 0; i < value.length(); i++) { - char c = value.charAt(i); - if (Character.isUpperCase(c)) { - if (!changed) { - // copy it over here - for (int j = 0; j < i; j++) { - sb.append(value.charAt(j)); - } - changed = true; - if (i == 0) { - sb.append(Character.toLowerCase(c)); - } else { - sb.append('_'); - sb.append(Character.toLowerCase(c)); - } - } else { - sb.append('_'); - sb.append(Character.toLowerCase(c)); - } - } else { - if (changed) { - sb.append(c); - } - } - } - if (!changed) { - return value; - } - return sb.toString(); - } - - protected static void headerToXContent(XContentBuilder builder, String key, List values) throws IOException { - if (values != null && values.isEmpty() == false) { - if (values.size() == 1) { - builder.field(key, values.get(0)); - } else { - builder.startArray(key); - for (String value : values) { - builder.value(value); - } - builder.endArray(); - } - } - } - - public static RestStatus status(Throwable t) { - if (t != null) { - if (t instanceof OpenSearchException) { - return ((OpenSearchException) t).status(); - } else if (t instanceof IllegalArgumentException) { - return RestStatus.BAD_REQUEST; - } else if (t instanceof JsonParseException) { - return RestStatus.BAD_REQUEST; - } else if (t instanceof OpenSearchRejectedExecutionException) { - return RestStatus.TOO_MANY_REQUESTS; - } else if (t instanceof NotXContentException) { - return RestStatus.BAD_REQUEST; - } - } - return RestStatus.INTERNAL_SERVER_ERROR; - } -} diff --git a/server/src/main/java/org/opensearch/ExceptionsHelper.java b/libs/core/src/main/java/org/opensearch/ExceptionsHelper.java similarity index 76% rename from server/src/main/java/org/opensearch/ExceptionsHelper.java rename to libs/core/src/main/java/org/opensearch/ExceptionsHelper.java index f4cf68b203a3a..d5c905f5dc528 100644 --- a/server/src/main/java/org/opensearch/ExceptionsHelper.java +++ b/libs/core/src/main/java/org/opensearch/ExceptionsHelper.java @@ -32,6 +32,9 @@ package org.opensearch; +import com.fasterxml.jackson.core.JsonParseException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; @@ -39,9 +42,14 @@ import org.opensearch.common.CheckedRunnable; import org.opensearch.common.CheckedSupplier; import org.opensearch.common.Nullable; +import org.opensearch.common.compress.NotXContentException; +import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; import org.opensearch.index.Index; +import org.opensearch.rest.RestStatus; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -56,12 +64,18 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import static org.opensearch.OpenSearchException.getExceptionSimpleClassName; + /** * Helper class for OpenSearch Exceptions * * @opensearch.internal */ -public final class ExceptionsHelper extends BaseExceptionsHelper { +public final class ExceptionsHelper { + protected static final Logger logger = LogManager.getLogger(ExceptionsHelper.class); + + // utility class: no ctor + private ExceptionsHelper() {} public static RuntimeException convertToRuntime(Exception e) { if (e instanceof RuntimeException) { @@ -77,6 +91,94 @@ public static OpenSearchException convertToOpenSearchException(Exception e) { return new OpenSearchException(e); } + public static RestStatus status(Throwable t) { + if (t != null) { + if (t instanceof OpenSearchException) { + return ((OpenSearchException) t).status(); + } else if (t instanceof IllegalArgumentException) { + return RestStatus.BAD_REQUEST; + } else if (t instanceof JsonParseException) { + return RestStatus.BAD_REQUEST; + } else if (t instanceof OpenSearchRejectedExecutionException) { + return RestStatus.TOO_MANY_REQUESTS; + } else if (t instanceof NotXContentException) { + return RestStatus.BAD_REQUEST; + } + } + return RestStatus.INTERNAL_SERVER_ERROR; + } + + public static String summaryMessage(Throwable t) { + if (t != null) { + if (t instanceof OpenSearchException) { + return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; + } else if (t instanceof IllegalArgumentException) { + return "Invalid argument"; + } else if (t instanceof JsonParseException) { + return "Failed to parse JSON"; + } else if (t instanceof OpenSearchRejectedExecutionException) { + return "Too many requests"; + } + } + return "Internal failure"; + } + + public static Throwable unwrapCause(Throwable t) { + int counter = 0; + Throwable result = t; + while (result instanceof OpenSearchWrapperException) { + if (result.getCause() == null) { + return result; + } + if (result.getCause() == result) { + return result; + } + if (counter++ > 10) { + // dear god, if we got more than 10 levels down, WTF? just bail + logger.warn("Exception cause unwrapping ran for 10 levels...", t); + return result; + } + result = result.getCause(); + } + return result; + } + + /** + * @deprecated Don't swallow exceptions, allow them to propagate. + */ + @Deprecated + public static String detailedMessage(Throwable t) { + if (t == null) { + return "Unknown"; + } + if (t.getCause() != null) { + StringBuilder sb = new StringBuilder(); + while (t != null) { + sb.append(getExceptionSimpleClassName(t)); + if (t.getMessage() != null) { + sb.append("["); + sb.append(t.getMessage()); + sb.append("]"); + } + sb.append("; "); + t = t.getCause(); + if (t != null) { + sb.append("nested: "); + } + } + return sb.toString(); + } else { + return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]"; + } + } + + public static String stackTrace(Throwable e) { + StringWriter stackTraceStringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stackTraceStringWriter); + e.printStackTrace(printWriter); + return stackTraceStringWriter.toString(); + } + public static String formatStackTrace(final StackTraceElement[] stackTrace) { return Arrays.stream(stackTrace).skip(1).map(e -> "\tat " + e).collect(Collectors.joining("\n")); } diff --git a/libs/core/src/main/java/org/opensearch/OpenSearchException.java b/libs/core/src/main/java/org/opensearch/OpenSearchException.java index e201fe7b1b788..707b53dfa58f9 100644 --- a/libs/core/src/main/java/org/opensearch/OpenSearchException.java +++ b/libs/core/src/main/java/org/opensearch/OpenSearchException.java @@ -37,6 +37,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.core.ParseField; import org.opensearch.core.common.Strings; import org.opensearch.core.common.logging.LoggerMessageFormat; import org.opensearch.core.xcontent.ToXContent; @@ -59,6 +60,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import static java.util.Collections.emptyMap; import static org.opensearch.OpenSearchException.OpenSearchExceptionHandleRegistry.registerExceptionHandle; import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; import static org.opensearch.common.xcontent.XContentParserUtils.ensureFieldName; @@ -72,14 +74,38 @@ */ public class OpenSearchException extends RuntimeException implements Writeable, ToXContentFragment { - protected static final String ERROR = "error"; - protected static final String ROOT_CAUSE = "root_cause"; - protected static final String RESOURCE_METADATA_TYPE_KEY = "opensearch.resource.type"; - protected static final String RESOURCE_METADATA_ID_KEY = "opensearch.resource.id"; protected static final Version UNKNOWN_VERSION_ADDED = Version.fromId(0); - protected static final String INDEX_METADATA_KEY = "opensearch.index"; - protected static final String SHARD_METADATA_KEY = "opensearch.shard"; - protected static final String INDEX_METADATA_KEY_UUID = "opensearch.index_uuid"; + + /** + * Passed in the {@link ToXContent.Params} of {@link #generateThrowableXContent(XContentBuilder, ToXContent.Params, Throwable)} + * to control if the {@code caused_by} element should render. Unlike most parameters to {@code toXContent} methods this parameter is + * internal only and not available as a URL parameter. + */ + private static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.cause.skip"; + /** + * Passed in the {@link ToXContent.Params} of {@link #generateThrowableXContent(XContentBuilder, ToXContent.Params, Throwable)} + * to control if the {@code stack_trace} element should render. Unlike most parameters to {@code toXContent} methods this parameter is + * internal only and not available as a URL parameter. Use the {@code error_trace} parameter instead. + */ + public static final String REST_EXCEPTION_SKIP_STACK_TRACE = "rest.exception.stacktrace.skip"; + public static final boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT = true; + private static final boolean REST_EXCEPTION_SKIP_CAUSE_DEFAULT = false; + private static final String RESOURCE_METADATA_TYPE_KEY = "opensearch.resource.type"; + private static final String RESOURCE_METADATA_ID_KEY = "opensearch.resource.id"; + private static final String INDEX_METADATA_KEY = "opensearch.index"; + private static final String INDEX_METADATA_KEY_UUID = "opensearch.index_uuid"; + private static final String SHARD_METADATA_KEY = "opensearch.shard"; + private static final String OPENSEARCH_PREFIX_KEY = "opensearch."; + + private static final String TYPE = "type"; + private static final String REASON = "reason"; + private static final String CAUSED_BY = "caused_by"; + private static final ParseField SUPPRESSED = new ParseField("suppressed"); + public static final String STACK_TRACE = "stack_trace"; + private static final String HEADER = "header"; + private static final String ERROR = "error"; + private static final String ROOT_CAUSE = "root_cause"; + protected final Map> metadata = new HashMap<>(); protected final Map> headers = new HashMap<>(); @@ -161,101 +187,6 @@ public void writeTo(final StreamOutput out) throws IOException { out.writeMapOfLists(metadata, StreamOutput::writeString, StreamOutput::writeString); } - /** - * Render any exception as a xcontent, encapsulated within a field or object named "error". The level of details that are rendered - * depends on the value of the "detailed" parameter: when it's false only a simple message based on the type and message of the - * exception is rendered. When it's true all detail are provided including guesses root causes, cause and potentially stack - * trace. - * - * This method is usually used when the {@link Exception} is rendered as a full XContent object, and its output can be parsed - * by the {@code #OpenSearchException.failureFromXContent(XContentParser)} method. - */ - public static void generateFailureXContent(XContentBuilder builder, ToXContent.Params params, @Nullable Exception e, boolean detailed) - throws IOException { - // No exception to render as an error - if (e == null) { - builder.field(ERROR, "unknown"); - return; - } - - // Render the exception with a simple message - if (detailed == false) { - Throwable t = e; - for (int counter = 0; counter < 10 && t != null; counter++) { - if (t instanceof OpenSearchException) { - break; - } - t = t.getCause(); - } - builder.field(ERROR, BaseExceptionsHelper.summaryMessage(t != null ? t : e)); - return; - } - - // Render the exception with all details - final OpenSearchException[] rootCauses = OpenSearchException.guessRootCauses(e); - builder.startObject(ERROR); - { - builder.startArray(ROOT_CAUSE); - for (OpenSearchException rootCause : rootCauses) { - builder.startObject(); - rootCause.toXContent( - builder, - new ToXContent.DelegatingMapParams(singletonMap(BaseExceptionsHelper.REST_EXCEPTION_SKIP_CAUSE, "true"), params) - ); - builder.endObject(); - } - builder.endArray(); - } - BaseExceptionsHelper.generateThrowableXContent(builder, params, e); - builder.endObject(); - } - - /** - * Returns the root cause of this exception or multiple if different shards caused different exceptions. - * If the given exception is not an instance of {@link OpenSearchException} an empty array - * is returned. - */ - public static OpenSearchException[] guessRootCauses(Throwable t) { - Throwable ex = BaseExceptionsHelper.unwrapCause(t); - if (ex instanceof OpenSearchException) { - // OpenSearchException knows how to guess its own root cause - return ((OpenSearchException) ex).guessRootCauses(); - } - if (ex instanceof XContentParseException) { - /* - * We'd like to unwrap parsing exceptions to the inner-most - * parsing exception because that is generally the most interesting - * exception to return to the user. If that exception is caused by - * an OpenSearchException we'd like to keep unwrapping because - * OpenSearchException instances tend to contain useful information - * for the user. - */ - Throwable cause = ex.getCause(); - if (cause != null) { - if (cause instanceof XContentParseException || cause instanceof OpenSearchException) { - return OpenSearchException.guessRootCauses(ex.getCause()); - } - } - } - return new OpenSearchException[] { new OpenSearchException(ex.getMessage(), ex) { - @Override - protected String getExceptionName() { - return BaseExceptionsHelper.getExceptionName(getCause()); - } - } }; - } - - static String buildMessage(String type, String reason, String stack) { - StringBuilder message = new StringBuilder("OpenSearch exception ["); - message.append(BaseExceptionsHelper.TYPE).append('=').append(type).append(", "); - message.append(BaseExceptionsHelper.REASON).append('=').append(reason); - if (stack != null) { - message.append(", ").append(BaseExceptionsHelper.STACK_TRACE).append('=').append(stack); - } - message.append(']'); - return message.toString(); - } - /** * Adds a new piece of metadata with the given key. * If the provided key is already present, the corresponding metadata will be replaced @@ -271,7 +202,7 @@ public void addMetadata(String key, String... values) { public void addMetadata(String key, List values) { // we need to enforce this otherwise bw comp doesn't work properly, as "opensearch." // was the previous criteria to split headers in two sets - if (key.startsWith(BaseExceptionsHelper.OPENSEARCH_PREFIX_KEY) == false) { + if (key.startsWith(OPENSEARCH_PREFIX_KEY) == false) { throw new IllegalArgumentException("exception metadata must start with [opensearch.], found [" + key + "] instead"); } this.metadata.put(key, values); @@ -303,7 +234,7 @@ protected Map> getMetadata() { public void addHeader(String key, List value) { // we need to enforce this otherwise bw comp doesn't work properly, as "opensearch." // was the previous criteria to split headers in two sets - if (key.startsWith(BaseExceptionsHelper.OPENSEARCH_PREFIX_KEY)) { + if (key.startsWith(OPENSEARCH_PREFIX_KEY)) { throw new IllegalArgumentException("exception headers must not start with [opensearch.], found [" + key + "] instead"); } this.headers.put(key, value); @@ -336,14 +267,26 @@ protected Map> getHeaders() { return headers; } + /** + * Returns the rest status code associated with this exception. + */ + public RestStatus status() { + Throwable cause = unwrapCause(); + if (cause == this) { + return RestStatus.INTERNAL_SERVER_ERROR; + } else { + return ExceptionsHelper.status(cause); + } + } + /** * Unwraps the actual cause from the exception for cases when the exception is a * {@link OpenSearchWrapperException}. * - * @see BaseExceptionsHelper#unwrapCause(Throwable) + * @see ExceptionsHelper#unwrapCause(Throwable) */ public Throwable unwrapCause() { - return BaseExceptionsHelper.unwrapCause(this); + return ExceptionsHelper.unwrapCause(this); } /** @@ -378,353 +321,162 @@ public Throwable getRootCause() { return rootCause; } - /** - * Renders additional per exception information into the XContent - */ - protected void metadataToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {} - - public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { - Throwable ex = BaseExceptionsHelper.unwrapCause(this); - if (ex != this) { - BaseExceptionsHelper.generateThrowableXContent(builder, params, this); - } else { - BaseExceptionsHelper.innerToXContent(builder, params, this, getExceptionName(), getMessage(), headers, metadata, getCause()); + @SuppressWarnings("unchecked") + public static OpenSearchException readException(T input, int id) throws IOException { + CheckedFunction opensearchException = (CheckedFunction< + T, + ? extends OpenSearchException, + IOException>) OpenSearchExceptionHandleRegistry.getSupplier(id); + if (opensearchException == null) { + throw new IllegalStateException("unknown exception for id: " + id); } - return builder; - } - - protected String getExceptionName() { - return BaseExceptionsHelper.getExceptionName(this); + return opensearchException.apply(input); } /** - * Returns the root cause of this exception or multiple if different shards caused different exceptions + * Returns true iff the given class is a registered for an exception to be read. */ - public OpenSearchException[] guessRootCauses() { - final Throwable cause = getCause(); - if (cause != null && cause instanceof OpenSearchException) { - return ((OpenSearchException) cause).guessRootCauses(); - } - return new OpenSearchException[] { this }; + public static boolean isRegistered(final Class exception, Version version) { + return OpenSearchExceptionHandleRegistry.isRegistered(exception, version); } - public void setResources(String type, String... id) { - assert type != null; - addMetadata(RESOURCE_METADATA_ID_KEY, id); - addMetadata(RESOURCE_METADATA_TYPE_KEY, type); + static Set> getRegisteredKeys() { // for testing + return OpenSearchExceptionHandleRegistry.getRegisteredKeys(); } - public List getResourceId() { - return getMetadata(RESOURCE_METADATA_ID_KEY); + /** + * Returns the serialization id the given exception. + */ + public static int getId(final Class exception) { + return OpenSearchExceptionHandleRegistry.getId(exception); } - public String getResourceType() { - List header = getMetadata(RESOURCE_METADATA_TYPE_KEY); - if (header != null && header.isEmpty() == false) { - assert header.size() == 1; - return header.get(0); + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + Throwable ex = ExceptionsHelper.unwrapCause(this); + if (ex != this) { + generateThrowableXContent(builder, params, this); + } else { + innerToXContent(builder, params, this, getExceptionName(), getMessage(), headers, metadata, getCause()); } - return null; + return builder; } - public String getIndexName() { - List index = getMetadata(INDEX_METADATA_KEY); - if (index != null && index.isEmpty() == false) { - return index.get(0); + protected static void innerToXContent( + XContentBuilder builder, + ToXContent.Params params, + Throwable throwable, + String type, + String message, + Map> headers, + Map> metadata, + Throwable cause + ) throws IOException { + builder.field(TYPE, type); + builder.field(REASON, message); + + for (Map.Entry> entry : metadata.entrySet()) { + headerToXContent(builder, entry.getKey().substring(OPENSEARCH_PREFIX_KEY.length()), entry.getValue()); } - return null; - } - /** - * Get index uuid as a string - * - * @deprecated remove in favor of Index#toString once Index class is moved to core library - */ - @Deprecated - private String getIndexUUID() { - List index_uuid = getMetadata(INDEX_METADATA_KEY_UUID); - if (index_uuid != null && index_uuid.isEmpty() == false) { - return index_uuid.get(0); + if (throwable instanceof OpenSearchException) { + OpenSearchException exception = (OpenSearchException) throwable; + exception.metadataToXContent(builder, params); } - return null; - } - /** - * Returns the rest status code associated with this exception. - */ - public RestStatus status() { - Throwable cause = unwrapCause(); - if (cause == this) { - return RestStatus.INTERNAL_SERVER_ERROR; - } else { - return BaseExceptionsHelper.status(cause); + if (params.paramAsBoolean(REST_EXCEPTION_SKIP_CAUSE, REST_EXCEPTION_SKIP_CAUSE_DEFAULT) == false) { + if (cause != null) { + builder.field(CAUSED_BY); + builder.startObject(); + generateThrowableXContent(builder, params, cause); + builder.endObject(); + } } - } - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - if (metadata.containsKey(INDEX_METADATA_KEY)) { - builder.append(getIndexString()); - if (metadata.containsKey(SHARD_METADATA_KEY)) { - builder.append('[').append(getShardIdString()).append(']'); + if (headers.isEmpty() == false) { + builder.startObject(HEADER); + for (Map.Entry> entry : headers.entrySet()) { + headerToXContent(builder, entry.getKey(), entry.getValue()); } - builder.append(' '); + builder.endObject(); } - return builder.append(BaseExceptionsHelper.detailedMessage(this).trim()).toString(); - } - /** - * Get index string - * - * @deprecated remove in favor of Index#toString once Index class is moved to core library - */ - @Deprecated - private String getIndexString() { - String uuid = getIndexUUID(); - if (uuid != null) { - String name = getIndexName(); - if (Strings.UNKNOWN_UUID_VALUE.equals(uuid)) { - return "[" + name + "]"; + if (params.paramAsBoolean(REST_EXCEPTION_SKIP_STACK_TRACE, REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT) == false) { + builder.field(STACK_TRACE, ExceptionsHelper.stackTrace(throwable)); + } + + Throwable[] allSuppressed = throwable.getSuppressed(); + if (allSuppressed.length > 0) { + builder.startArray(SUPPRESSED.getPreferredName()); + for (Throwable suppressed : allSuppressed) { + builder.startObject(); + generateThrowableXContent(builder, params, suppressed); + builder.endObject(); } - return "[" + name + "/" + uuid + "]"; + builder.endArray(); } - return null; } - /** - * Get shard id string - * - * @deprecated remove in favor of ShardId#toString once ShardId class is moved to core library - */ - @Deprecated - private String getShardIdString() { - String indexName = getIndexName(); - List shard = getMetadata(SHARD_METADATA_KEY); - if (indexName != null && shard != null && shard.isEmpty() == false) { - return "[" + indexName + "][" + Integer.parseInt(shard.get(0)) + "]"; + protected static void headerToXContent(XContentBuilder builder, String key, List values) throws IOException { + if (values != null && values.isEmpty() == false) { + if (values.size() == 1) { + builder.field(key, values.get(0)); + } else { + builder.startArray(key); + for (String value : values) { + builder.value(value); + } + builder.endArray(); + } } - return null; } /** - * Returns an array of all registered handle IDs. These are the IDs for every registered - * exception. - * - * @return an array of all registered handle IDs + * Renders additional per exception information into the XContent */ - static int[] ids() { - return OpenSearchExceptionHandleRegistry.ids().stream().mapToInt(i -> i).toArray(); - } + protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException {} /** - * Returns an array of all registered pairs of handle IDs and exception classes. These pairs are - * provided for every registered exception. - * - * @return an array of all registered pairs of handle IDs and exception classes + * Generate a {@link OpenSearchException} from a {@link XContentParser}. This does not + * return the original exception type (ie NodeClosedException for example) but just wraps + * the type, the reason and the cause of the exception. It also recursively parses the + * tree structure of the cause, returning it as a tree structure of {@link OpenSearchException} + * instances. */ - @SuppressWarnings("unchecked") - static Tuple>[] classes() { - final Tuple>[] ts = OpenSearchExceptionHandleRegistry.handles() - .stream() - .map(h -> Tuple.tuple(h.id, h.exceptionClass)) - .toArray(Tuple[]::new); - return ts; + public static OpenSearchException fromXContent(XContentParser parser) throws IOException { + XContentParser.Token token = parser.nextToken(); + ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); + return innerFromXContent(parser, false); } - public Index getIndex() { - List index = getMetadata(INDEX_METADATA_KEY); - if (index != null && index.isEmpty() == false) { - List index_uuid = getMetadata(INDEX_METADATA_KEY_UUID); - return new Index(index.get(0), index_uuid.get(0)); - } + public static OpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException { + XContentParser.Token token = parser.currentToken(); + ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - return null; - } + String type = null, reason = null, stack = null; + OpenSearchException cause = null; + Map> metadata = new HashMap<>(); + Map> headers = new HashMap<>(); + List rootCauses = new ArrayList<>(); + List suppressed = new ArrayList<>(); - public void setIndex(Index index) { - if (index != null) { - addMetadata(INDEX_METADATA_KEY, index.getName()); - addMetadata(INDEX_METADATA_KEY_UUID, index.getUUID()); - } - } - - public void setIndex(String index) { - if (index != null) { - setIndex(new Index(index, Strings.UNKNOWN_UUID_VALUE)); - } - } - - public ShardId getShardId() { - List shard = getMetadata(SHARD_METADATA_KEY); - if (shard != null && shard.isEmpty() == false) { - return new ShardId(getIndex(), Integer.parseInt(shard.get(0))); - } - return null; - } - - public void setShard(ShardId shardId) { - if (shardId != null) { - setIndex(shardId.getIndex()); - addMetadata(SHARD_METADATA_KEY, Integer.toString(shardId.id())); - } - } - - /** - * This is the list of Exceptions OpenSearch can throw over the wire or save into a corruption marker. Each value in the enum is a - * single exception tying the Class to an id for use of the encode side and the id back to a constructor for use on the decode side. As - * such its ok if the exceptions to change names so long as their constructor can still read the exception. Each exception is listed - * in id order. If you want to remove an exception leave a tombstone comment and mark the id as null in - * ExceptionSerializationTests.testIds.ids. - * - * @opensearch.internal - */ - protected static class OpenSearchExceptionHandle { - final Class exceptionClass; - final CheckedFunction constructor; - final int id; - final Version versionAdded; - - OpenSearchExceptionHandle( - Class exceptionClass, - CheckedFunction constructor, - int id, - Version versionAdded - ) { - // We need the exceptionClass because you can't dig it out of the constructor reliably. - this.exceptionClass = exceptionClass; - this.constructor = constructor; - this.versionAdded = versionAdded; - this.id = id; - } - } - - @SuppressWarnings("unchecked") - public static OpenSearchException readException(T input, int id) throws IOException { - CheckedFunction opensearchException = (CheckedFunction< - T, - ? extends OpenSearchException, - IOException>) OpenSearchExceptionHandleRegistry.getSupplier(id); - if (opensearchException == null) { - throw new IllegalStateException("unknown exception for id: " + id); - } - return opensearchException.apply(input); - } - - /** - * Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and - * adds it to the given exception. - */ - public static T readStackTrace(T throwable, StreamInput in) throws IOException { - throwable.setStackTrace(in.readArray(i -> { - final String declaringClasss = i.readString(); - final String fileName = i.readOptionalString(); - final String methodName = i.readString(); - final int lineNumber = i.readVInt(); - return new StackTraceElement(declaringClasss, methodName, fileName, lineNumber); - }, StackTraceElement[]::new)); - - int numSuppressed = in.readVInt(); - for (int i = 0; i < numSuppressed; i++) { - throwable.addSuppressed(in.readException()); - } - return throwable; - } - - /** - * Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream. - */ - public static T writeStackTraces( - T throwable, - StreamOutput out, - Writer exceptionWriter - ) throws IOException { - out.writeArray((o, v) -> { - o.writeString(v.getClassName()); - o.writeOptionalString(v.getFileName()); - o.writeString(v.getMethodName()); - o.writeVInt(v.getLineNumber()); - }, throwable.getStackTrace()); - out.writeArray(exceptionWriter, throwable.getSuppressed()); - return throwable; - } - - /** - * Returns the serialization id the given exception. - */ - public static int getId(final Class exception) { - return OpenSearchExceptionHandleRegistry.getId(exception); - } - - /** - * Returns true iff the given class is a registered for an exception to be read. - */ - public static boolean isRegistered(final Class exception, Version version) { - return OpenSearchExceptionHandleRegistry.isRegistered(exception, version); - } - - /** - * Generate a {@link OpenSearchException} from a {@link XContentParser}. This does not - * return the original exception type (ie NodeClosedException for example) but just wraps - * the type, the reason and the cause of the exception. It also recursively parses the - * tree structure of the cause, returning it as a tree structure of {@link OpenSearchException} - * instances. - */ - public static OpenSearchException fromXContent(XContentParser parser) throws IOException { - XContentParser.Token token = parser.nextToken(); - ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - return innerFromXContent(parser, false); - } - - /** - * Parses the output of {@link #generateFailureXContent(XContentBuilder, Params, Exception, boolean)} - */ - public static OpenSearchException failureFromXContent(XContentParser parser) throws IOException { - XContentParser.Token token = parser.currentToken(); - ensureFieldName(parser, token, ERROR); - - token = parser.nextToken(); - if (token.isValue()) { - return new OpenSearchException(buildMessage("exception", parser.text(), null)) { - }; - } - - ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); - token = parser.nextToken(); - - // Root causes are parsed in the innerFromXContent() and are added as suppressed exceptions. - return innerFromXContent(parser, true); - } - - public static OpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException { - XContentParser.Token token = parser.currentToken(); - ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - - String type = null, reason = null, stack = null; - OpenSearchException cause = null; - Map> metadata = new HashMap<>(); - Map> headers = new HashMap<>(); - List rootCauses = new ArrayList<>(); - List suppressed = new ArrayList<>(); - - for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) { - String currentFieldName = parser.currentName(); - token = parser.nextToken(); + for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) { + String currentFieldName = parser.currentName(); + token = parser.nextToken(); if (token.isValue()) { - if (BaseExceptionsHelper.TYPE.equals(currentFieldName)) { + if (TYPE.equals(currentFieldName)) { type = parser.text(); - } else if (BaseExceptionsHelper.REASON.equals(currentFieldName)) { + } else if (REASON.equals(currentFieldName)) { reason = parser.text(); - } else if (BaseExceptionsHelper.STACK_TRACE.equals(currentFieldName)) { + } else if (STACK_TRACE.equals(currentFieldName)) { stack = parser.text(); } else if (token == XContentParser.Token.VALUE_STRING) { metadata.put(currentFieldName, Collections.singletonList(parser.text())); } } else if (token == XContentParser.Token.START_OBJECT) { - if (BaseExceptionsHelper.CAUSED_BY.equals(currentFieldName)) { + if (CAUSED_BY.equals(currentFieldName)) { cause = fromXContent(parser); - } else if (BaseExceptionsHelper.HEADER.equals(currentFieldName)) { + } else if (HEADER.equals(currentFieldName)) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); @@ -757,7 +509,7 @@ public static OpenSearchException innerFromXContent(XContentParser parser, boole while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { rootCauses.add(fromXContent(parser)); } - } else if (BaseExceptionsHelper.SUPPRESSED.match(currentFieldName, parser.getDeprecationHandler())) { + } else if (SUPPRESSED.match(currentFieldName, parser.getDeprecationHandler())) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { suppressed.add(fromXContent(parser)); } @@ -791,7 +543,7 @@ public static OpenSearchException innerFromXContent(XContentParser parser, boole // by addMetadata. The prefix will get stripped out when printing metadata out so it will be effectively invisible. // TODO move subclasses that print out simple metadata to using addMetadata directly and support also numbers and booleans. // TODO rename metadataToXContent and have only SearchPhaseExecutionException use it, which prints out complex objects - e.addMetadata(BaseExceptionsHelper.OPENSEARCH_PREFIX_KEY + entry.getKey(), entry.getValue()); + e.addMetadata(OPENSEARCH_PREFIX_KEY + entry.getKey(), entry.getValue()); } for (Map.Entry> header : headers.entrySet()) { e.addHeader(header.getKey(), header.getValue()); @@ -808,8 +560,366 @@ public static OpenSearchException innerFromXContent(XContentParser parser, boole return e; } - static Set> getRegisteredKeys() { // for testing - return OpenSearchExceptionHandleRegistry.getRegisteredKeys(); + /** + * Static toXContent helper method that renders {@link OpenSearchException} or {@link Throwable} instances + * as XContent, delegating the rendering to {@link OpenSearchException#toXContent(XContentBuilder, ToXContent.Params)} + * or {@link #innerToXContent(XContentBuilder, ToXContent.Params, Throwable, String, String, Map, Map, Throwable)}. + * + * This method is usually used when the {@link Throwable} is rendered as a part of another XContent object, and its result can + * be parsed back using the {@code OpenSearchException.fromXContent(XContentParser)} method. + */ + public static void generateThrowableXContent(XContentBuilder builder, ToXContent.Params params, Throwable t) throws IOException { + t = ExceptionsHelper.unwrapCause(t); + + if (t instanceof OpenSearchException) { + ((OpenSearchException) t).toXContent(builder, params); + } else { + innerToXContent(builder, params, t, getExceptionName(t), t.getMessage(), emptyMap(), emptyMap(), t.getCause()); + } + } + + /** + * Render any exception as a xcontent, encapsulated within a field or object named "error". The level of details that are rendered + * depends on the value of the "detailed" parameter: when it's false only a simple message based on the type and message of the + * exception is rendered. When it's true all detail are provided including guesses root causes, cause and potentially stack + * trace. + * + * This method is usually used when the {@link Exception} is rendered as a full XContent object, and its output can be parsed + * by the {@code #OpenSearchException.failureFromXContent(XContentParser)} method. + */ + public static void generateFailureXContent(XContentBuilder builder, ToXContent.Params params, @Nullable Exception e, boolean detailed) + throws IOException { + // No exception to render as an error + if (e == null) { + builder.field(ERROR, "unknown"); + return; + } + + // Render the exception with a simple message + if (detailed == false) { + Throwable t = e; + for (int counter = 0; counter < 10 && t != null; counter++) { + if (t instanceof OpenSearchException) { + break; + } + t = t.getCause(); + } + builder.field(ERROR, ExceptionsHelper.summaryMessage(t != null ? t : e)); + return; + } + + // Render the exception with all details + final OpenSearchException[] rootCauses = OpenSearchException.guessRootCauses(e); + builder.startObject(ERROR); + { + builder.startArray(ROOT_CAUSE); + for (OpenSearchException rootCause : rootCauses) { + builder.startObject(); + rootCause.toXContent(builder, new ToXContent.DelegatingMapParams(singletonMap(REST_EXCEPTION_SKIP_CAUSE, "true"), params)); + builder.endObject(); + } + builder.endArray(); + } + generateThrowableXContent(builder, params, e); + builder.endObject(); + } + + /** + * Parses the output of {@link #generateFailureXContent(XContentBuilder, Params, Exception, boolean)} + */ + public static OpenSearchException failureFromXContent(XContentParser parser) throws IOException { + XContentParser.Token token = parser.currentToken(); + ensureFieldName(parser, token, ERROR); + + token = parser.nextToken(); + if (token.isValue()) { + return new OpenSearchException(buildMessage("exception", parser.text(), null)) { + }; + } + + ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); + token = parser.nextToken(); + + // Root causes are parsed in the innerFromXContent() and are added as suppressed exceptions. + return innerFromXContent(parser, true); + } + + /** + * Returns the root cause of this exception or multiple if different shards caused different exceptions + */ + public OpenSearchException[] guessRootCauses() { + final Throwable cause = getCause(); + if (cause != null && cause instanceof OpenSearchException) { + return ((OpenSearchException) cause).guessRootCauses(); + } + return new OpenSearchException[] { this }; + } + + /** + * Returns the root cause of this exception or multiple if different shards caused different exceptions. + * If the given exception is not an instance of {@link OpenSearchException} an empty array + * is returned. + */ + public static OpenSearchException[] guessRootCauses(Throwable t) { + Throwable ex = ExceptionsHelper.unwrapCause(t); + if (ex instanceof OpenSearchException) { + // OpenSearchException knows how to guess its own root cause + return ((OpenSearchException) ex).guessRootCauses(); + } + if (ex instanceof XContentParseException) { + /* + * We'd like to unwrap parsing exceptions to the inner-most + * parsing exception because that is generally the most interesting + * exception to return to the user. If that exception is caused by + * an OpenSearchException we'd like to keep unwrapping because + * OpenSearchException instances tend to contain useful information + * for the user. + */ + Throwable cause = ex.getCause(); + if (cause != null) { + if (cause instanceof XContentParseException || cause instanceof OpenSearchException) { + return OpenSearchException.guessRootCauses(ex.getCause()); + } + } + } + return new OpenSearchException[] { new OpenSearchException(ex.getMessage(), ex) { + @Override + protected String getExceptionName() { + return getExceptionName(getCause()); + } + } }; + } + + protected String getExceptionName() { + return getExceptionName(this); + } + + /** + * Returns an underscore case name for the given exception. This method strips {@code OpenSearch} prefixes from exception names. + */ + public static String getExceptionName(Throwable ex) { + String simpleName = getExceptionSimpleClassName(ex); + if (simpleName.startsWith("OpenSearch")) { + simpleName = simpleName.substring("OpenSearch".length()); + } + // TODO: do we really need to make the exception name in underscore casing? + return toUnderscoreCase(simpleName); + } + + public static String getExceptionSimpleClassName(final Throwable ex) { + String simpleName = ex.getClass().getSimpleName(); + if (Strings.isEmpty(simpleName)) { + simpleName = "OpenSearchException"; + } + return simpleName; + } + + static String buildMessage(String type, String reason, String stack) { + StringBuilder message = new StringBuilder("OpenSearch exception ["); + message.append(TYPE).append('=').append(type).append(", "); + message.append(REASON).append('=').append(reason); + if (stack != null) { + message.append(", ").append(STACK_TRACE).append('=').append(stack); + } + message.append(']'); + return message.toString(); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + if (metadata.containsKey(INDEX_METADATA_KEY)) { + builder.append(getIndex()); + if (metadata.containsKey(SHARD_METADATA_KEY)) { + builder.append('[').append(getShardId()).append(']'); + } + builder.append(' '); + } + return builder.append(ExceptionsHelper.detailedMessage(this).trim()).toString(); + } + + /** + * Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and + * adds it to the given exception. + */ + public static T readStackTrace(T throwable, StreamInput in) throws IOException { + throwable.setStackTrace(in.readArray(i -> { + final String declaringClasss = i.readString(); + final String fileName = i.readOptionalString(); + final String methodName = i.readString(); + final int lineNumber = i.readVInt(); + return new StackTraceElement(declaringClasss, methodName, fileName, lineNumber); + }, StackTraceElement[]::new)); + + int numSuppressed = in.readVInt(); + for (int i = 0; i < numSuppressed; i++) { + throwable.addSuppressed(in.readException()); + } + return throwable; + } + + /** + * Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream. + */ + public static T writeStackTraces( + T throwable, + StreamOutput out, + Writer exceptionWriter + ) throws IOException { + out.writeArray((o, v) -> { + o.writeString(v.getClassName()); + o.writeOptionalString(v.getFileName()); + o.writeString(v.getMethodName()); + o.writeVInt(v.getLineNumber()); + }, throwable.getStackTrace()); + out.writeArray(exceptionWriter, throwable.getSuppressed()); + return throwable; + } + + public void setResources(String type, String... id) { + assert type != null; + addMetadata(RESOURCE_METADATA_ID_KEY, id); + addMetadata(RESOURCE_METADATA_TYPE_KEY, type); + } + + public List getResourceId() { + return getMetadata(RESOURCE_METADATA_ID_KEY); + } + + public String getResourceType() { + List header = getMetadata(RESOURCE_METADATA_TYPE_KEY); + if (header != null && header.isEmpty() == false) { + assert header.size() == 1; + return header.get(0); + } + return null; + } + + // lower cases and adds underscores to transitions in a name + private static String toUnderscoreCase(String value) { + StringBuilder sb = new StringBuilder(); + boolean changed = false; + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (Character.isUpperCase(c)) { + if (!changed) { + // copy it over here + for (int j = 0; j < i; j++) { + sb.append(value.charAt(j)); + } + changed = true; + if (i == 0) { + sb.append(Character.toLowerCase(c)); + } else { + sb.append('_'); + sb.append(Character.toLowerCase(c)); + } + } else { + sb.append('_'); + sb.append(Character.toLowerCase(c)); + } + } else { + if (changed) { + sb.append(c); + } + } + } + if (!changed) { + return value; + } + return sb.toString(); + } + + /** + * Returns an array of all registered handle IDs. These are the IDs for every registered + * exception. + * + * @return an array of all registered handle IDs + */ + static int[] ids() { + return OpenSearchExceptionHandleRegistry.ids().stream().mapToInt(i -> i).toArray(); + } + + /** + * Returns an array of all registered pairs of handle IDs and exception classes. These pairs are + * provided for every registered exception. + * + * @return an array of all registered pairs of handle IDs and exception classes + */ + @SuppressWarnings("unchecked") + static Tuple>[] classes() { + final Tuple>[] ts = OpenSearchExceptionHandleRegistry.handles() + .stream() + .map(h -> Tuple.tuple(h.id, h.exceptionClass)) + .toArray(Tuple[]::new); + return ts; + } + + public Index getIndex() { + List index = getMetadata(INDEX_METADATA_KEY); + if (index != null && index.isEmpty() == false) { + List index_uuid = getMetadata(INDEX_METADATA_KEY_UUID); + return new Index(index.get(0), index_uuid.get(0)); + } + + return null; + } + + public void setIndex(Index index) { + if (index != null) { + addMetadata(INDEX_METADATA_KEY, index.getName()); + addMetadata(INDEX_METADATA_KEY_UUID, index.getUUID()); + } + } + + public void setIndex(String index) { + if (index != null) { + setIndex(new Index(index, Strings.UNKNOWN_UUID_VALUE)); + } + } + + public ShardId getShardId() { + List shard = getMetadata(SHARD_METADATA_KEY); + if (shard != null && shard.isEmpty() == false) { + return new ShardId(getIndex(), Integer.parseInt(shard.get(0))); + } + return null; + } + + public void setShard(ShardId shardId) { + if (shardId != null) { + setIndex(shardId.getIndex()); + addMetadata(SHARD_METADATA_KEY, Integer.toString(shardId.id())); + } + } + + /** + * This is the list of Exceptions OpenSearch can throw over the wire or save into a corruption marker. Each value in the enum is a + * single exception tying the Class to an id for use of the encode side and the id back to a constructor for use on the decode side. As + * such its ok if the exceptions to change names so long as their constructor can still read the exception. Each exception is listed + * in id order. If you want to remove an exception leave a tombstone comment and mark the id as null in + * ExceptionSerializationTests.testIds.ids. + * + * @opensearch.internal + */ + protected static class OpenSearchExceptionHandle { + final Class exceptionClass; + final CheckedFunction constructor; + final int id; + final Version versionAdded; + + OpenSearchExceptionHandle( + Class exceptionClass, + CheckedFunction constructor, + int id, + Version versionAdded + ) { + // We need the exceptionClass because you can't dig it out of the constructor reliably. + this.exceptionClass = exceptionClass; + this.constructor = constructor; + this.versionAdded = versionAdded; + this.id = id; + } } /** diff --git a/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java index 3f958a50661bd..71f0980e56d4b 100644 --- a/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java +++ b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java @@ -32,7 +32,7 @@ package org.opensearch.action.support; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.ShardOperationFailedException; import org.opensearch.core.ParseField; @@ -46,7 +46,7 @@ import java.io.IOException; -import static org.opensearch.BaseExceptionsHelper.detailedMessage; +import static org.opensearch.ExceptionsHelper.detailedMessage; import static org.opensearch.core.xcontent.ConstructingObjectParser.constructorArg; /** @@ -93,7 +93,7 @@ public DefaultShardOperationFailedException(OpenSearchException e) { } public DefaultShardOperationFailedException(String index, int shardId, Throwable cause) { - super(index, shardId, BaseExceptionsHelper.detailedMessage(cause), BaseExceptionsHelper.status(cause), cause); + super(index, shardId, ExceptionsHelper.detailedMessage(cause), ExceptionsHelper.status(cause), cause); } public static DefaultShardOperationFailedException readShardOperationFailed(StreamInput in) throws IOException { @@ -135,7 +135,7 @@ protected XContentBuilder innerToXContent(XContentBuilder builder, Params params builder.field("status", status.name()); if (reason != null) { builder.startObject("reason"); - BaseExceptionsHelper.generateThrowableXContent(builder, params, cause); + OpenSearchException.generateThrowableXContent(builder, params, cause); builder.endObject(); } return builder; diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java b/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java index 590f9c2a03d57..967957afc8c20 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/NotSerializableExceptionWrapper.java @@ -32,7 +32,7 @@ package org.opensearch.common.io.stream; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.rest.RestStatus; @@ -53,9 +53,9 @@ public final class NotSerializableExceptionWrapper extends OpenSearchException { private final RestStatus status; public NotSerializableExceptionWrapper(Throwable other) { - super(BaseExceptionsHelper.getExceptionName(other) + ": " + other.getMessage(), other.getCause()); - this.name = BaseExceptionsHelper.getExceptionName(other); - this.status = BaseExceptionsHelper.status(other); + super(OpenSearchException.getExceptionName(other) + ": " + other.getMessage(), other.getCause()); + this.name = OpenSearchException.getExceptionName(other); + this.status = ExceptionsHelper.status(other); setStackTrace(other.getStackTrace()); for (Throwable otherSuppressed : other.getSuppressed()) { addSuppressed(otherSuppressed); diff --git a/modules/geo/src/test/java/org/opensearch/geo/search/aggregations/bucket/geogrid/GeoTileGridParserTests.java b/modules/geo/src/test/java/org/opensearch/geo/search/aggregations/bucket/geogrid/GeoTileGridParserTests.java index a39f66f571d0a..0bf41f37c45a7 100644 --- a/modules/geo/src/test/java/org/opensearch/geo/search/aggregations/bucket/geogrid/GeoTileGridParserTests.java +++ b/modules/geo/src/test/java/org/opensearch/geo/search/aggregations/bucket/geogrid/GeoTileGridParserTests.java @@ -31,7 +31,7 @@ package org.opensearch.geo.search.aggregations.bucket.geogrid; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.core.xcontent.XContentParseException; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; @@ -77,7 +77,7 @@ public void testParseErrorOnBooleanPrecision() throws Exception { () -> GeoTileGridAggregationBuilder.PARSER.parse(stParser, "geotile_grid") ); assertThat( - BaseExceptionsHelper.detailedMessage(e), + ExceptionsHelper.detailedMessage(e), containsString("[geotile_grid] precision doesn't support values of type: VALUE_BOOLEAN") ); } diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java index e11ad3b5013c1..61336156a83d0 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -33,7 +33,6 @@ package org.opensearch.index.reindex; import org.apache.lucene.search.TotalHits; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.Version; @@ -216,7 +215,7 @@ public void testStartRetriesOnRejectionButFailsOnTooManyRejections() throws Exce assertBusy(() -> assertEquals(testRequest.getMaxRetries() + 1, client.searchAttempts.get())); assertBusy(() -> assertTrue(listener.isDone())); ExecutionException e = expectThrows(ExecutionException.class, () -> listener.get()); - assertThat(BaseExceptionsHelper.stackTrace(e), containsString(OpenSearchRejectedExecutionException.class.getSimpleName())); + assertThat(ExceptionsHelper.stackTrace(e), containsString(OpenSearchRejectedExecutionException.class.getSimpleName())); assertNull("There shouldn't be a search attempt pending that we didn't reject", client.lastSearch.get()); assertEquals(testRequest.getMaxRetries(), testTask.getStatus().getSearchRetries()); } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/RejectionActionIT.java b/server/src/internalClusterTest/java/org/opensearch/action/RejectionActionIT.java index f2f55b238ab7c..bda24b48b7f10 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/RejectionActionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/RejectionActionIT.java @@ -32,7 +32,7 @@ package org.opensearch.action; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; import org.opensearch.action.search.SearchType; @@ -105,7 +105,7 @@ public void onFailure(Exception e) { } } else { Exception t = (Exception) response; - Throwable unwrap = BaseExceptionsHelper.unwrapCause(t); + Throwable unwrap = ExceptionsHelper.unwrapCause(t); if (unwrap instanceof SearchPhaseExecutionException) { SearchPhaseExecutionException e = (SearchPhaseExecutionException) unwrap; for (ShardSearchFailure failure : e.shardFailures()) { diff --git a/server/src/internalClusterTest/java/org/opensearch/action/search/TransportSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/action/search/TransportSearchIT.java index 895d7ebea88b6..8cd7bdeb0c822 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/search/TransportSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/search/TransportSearchIT.java @@ -36,7 +36,7 @@ import org.apache.lucene.search.CollectionTerminatedException; import org.apache.lucene.search.ScoreMode; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.admin.cluster.node.stats.NodeStats; import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; @@ -415,7 +415,7 @@ public void onFailure(Exception e) { SearchPhaseExecutionException.class, () -> client.prepareSearch("test").addAggregation(new TestAggregationBuilder("test")).get() ); - assertThat(BaseExceptionsHelper.unwrapCause(exc).getCause().getMessage(), containsString("")); + assertThat(ExceptionsHelper.unwrapCause(exc).getCause().getMessage(), containsString("")); }); final AtomicArray exceptions = new AtomicArray<>(10); @@ -443,7 +443,7 @@ public void onFailure(Exception exc) { latch.await(); assertThat(exceptions.asList().size(), equalTo(10)); for (Exception exc : exceptions.asList()) { - assertThat(BaseExceptionsHelper.unwrapCause(exc).getCause().getMessage(), containsString("")); + assertThat(ExceptionsHelper.unwrapCause(exc).getCause().getMessage(), containsString("")); } assertBusy(() -> assertThat(requestBreakerUsed(), equalTo(0L))); } finally { @@ -482,7 +482,7 @@ public void onFailure(Exception exc) { latch.await(); assertThat(exceptions.asList().size(), equalTo(10)); for (Exception exc : exceptions.asList()) { - assertThat(BaseExceptionsHelper.unwrapCause(exc).getCause().getMessage(), containsString("boom")); + assertThat(ExceptionsHelper.unwrapCause(exc).getCause().getMessage(), containsString("boom")); } assertBusy(() -> assertThat(requestBreakerUsed(), equalTo(0L))); } diff --git a/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java index 872da7bb12b8e..8ede3e25b2e1a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java @@ -32,7 +32,7 @@ package org.opensearch.blocks; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.admin.indices.create.CreateIndexResponse; import org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse; @@ -428,7 +428,7 @@ public void testAddBlockWhileIndexingDocuments() throws Exception { try { try (BackgroundIndexer indexer = new BackgroundIndexer(indexName, "_doc", client(), 1000)) { indexer.setFailureAssertion(t -> { - Throwable cause = BaseExceptionsHelper.unwrapCause(t); + Throwable cause = ExceptionsHelper.unwrapCause(t); assertThat(cause, instanceOf(ClusterBlockException.class)); ClusterBlockException e = (ClusterBlockException) cause; assertThat(e.blocks(), hasSize(1)); @@ -474,7 +474,7 @@ public void testAddBlockWhileDeletingIndices() throws Exception { final APIBlock block = randomAddableBlock(); Consumer exceptionConsumer = t -> { - Throwable cause = BaseExceptionsHelper.unwrapCause(t); + Throwable cause = ExceptionsHelper.unwrapCause(t); if (cause instanceof ClusterBlockException) { ClusterBlockException e = (ClusterBlockException) cause; assertThat(e.blocks(), hasSize(1)); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java index 6ef3848cec9bb..2dc6b2085b866 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java @@ -32,7 +32,7 @@ package org.opensearch.indices.memory.breaker; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.admin.cluster.node.stats.NodeStats; import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.opensearch.action.bulk.BulkItemResponse; @@ -421,7 +421,7 @@ public void testLimitsRequestSize() { } else { // each item must have failed with CircuitBreakingException for (BulkItemResponse bulkItemResponse : response) { - Throwable cause = BaseExceptionsHelper.unwrapCause(bulkItemResponse.getFailure().getCause()); + Throwable cause = ExceptionsHelper.unwrapCause(bulkItemResponse.getFailure().getCause()); assertThat(cause, instanceOf(CircuitBreakingException.class)); assertEquals(((CircuitBreakingException) cause).getByteLimit(), inFlightRequestsLimit.getBytes()); } diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/state/CloseIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/state/CloseIndexIT.java index 995f11bcd79c6..28bd5a6ae252d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/state/CloseIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/state/CloseIndexIT.java @@ -32,7 +32,7 @@ package org.opensearch.indices.state; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.admin.indices.close.CloseIndexRequestBuilder; import org.opensearch.action.admin.indices.close.CloseIndexResponse; @@ -647,7 +647,7 @@ static void assertIndexIsOpened(final String... indices) { } static void assertException(final Throwable throwable, final String indexName) { - final Throwable t = BaseExceptionsHelper.unwrapCause(throwable); + final Throwable t = ExceptionsHelper.unwrapCause(throwable); if (t instanceof ClusterBlockException) { ClusterBlockException clusterBlockException = (ClusterBlockException) t; assertThat(clusterBlockException.blocks(), hasSize(1)); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/DerivativeIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/DerivativeIT.java index eb6153493323c..406c57d044259 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/DerivativeIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/DerivativeIT.java @@ -32,7 +32,7 @@ package org.opensearch.search.aggregations.pipeline; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -639,7 +639,7 @@ public void testSingleValueAggDerivative_invalidPath() throws Exception { .get(); fail("Expected an Exception but didn't get one"); } catch (Exception e) { - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause == null) { throw e; } else if (cause instanceof SearchPhaseExecutionException) { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/ExtendedStatsBucketIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/ExtendedStatsBucketIT.java index fc4a2908ae563..85fe794b05fc6 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/ExtendedStatsBucketIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/ExtendedStatsBucketIT.java @@ -32,7 +32,7 @@ package org.opensearch.search.aggregations.pipeline; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -489,7 +489,7 @@ public void testBadSigmaAsSubAgg() throws Exception { ) .get() ); - Throwable cause = BaseExceptionsHelper.unwrapCause(ex); + Throwable cause = ExceptionsHelper.unwrapCause(ex); if (cause == null) { throw ex; } else if (cause instanceof SearchPhaseExecutionException) { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/PercentilesBucketIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/PercentilesBucketIT.java index 4d7fa05ba5043..1da079781dc63 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/PercentilesBucketIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/PercentilesBucketIT.java @@ -32,7 +32,7 @@ package org.opensearch.search.aggregations.pipeline; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.action.search.SearchResponse; @@ -439,7 +439,7 @@ public void testBadPercents() throws Exception { fail("Illegal percent's were provided but no exception was thrown."); } catch (Exception e) { - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause == null) { throw e; } else if (cause instanceof SearchPhaseExecutionException) { @@ -474,7 +474,7 @@ public void testBadPercents_asSubAgg() throws Exception { fail("Illegal percent's were provided but no exception was thrown."); } catch (Exception e) { - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause == null) { throw e; } else if (cause instanceof SearchPhaseExecutionException) { diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SharedClusterSnapshotRestoreIT.java index 767fd5ea8fde3..9736aba92f3d1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -34,7 +34,7 @@ import org.apache.lucene.util.BytesRef; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.ActionFuture; @@ -1986,7 +1986,7 @@ public void testSnapshotSucceedsAfterSnapshotFailure() throws Exception { } } catch (SnapshotException | RepositoryException ex) { // sometimes, the snapshot will fail with a top level I/O exception - assertThat(BaseExceptionsHelper.stackTrace(ex), containsString("Random IOException")); + assertThat(ExceptionsHelper.stackTrace(ex), containsString("Random IOException")); } logger.info("--> snapshot with no I/O failures"); diff --git a/server/src/main/java/org/opensearch/OpenSearchSecurityException.java b/server/src/main/java/org/opensearch/OpenSearchSecurityException.java index c663dc0822cfd..6f725573e71ce 100644 --- a/server/src/main/java/org/opensearch/OpenSearchSecurityException.java +++ b/server/src/main/java/org/opensearch/OpenSearchSecurityException.java @@ -53,7 +53,7 @@ public OpenSearchSecurityException(String msg, RestStatus status, Throwable caus * Build the exception with the status derived from the cause. */ public OpenSearchSecurityException(String msg, Exception cause, Object... args) { - this(msg, BaseExceptionsHelper.status(cause), cause, args); + this(msg, ExceptionsHelper.status(cause), cause, args); } /** diff --git a/server/src/main/java/org/opensearch/action/TaskOperationFailure.java b/server/src/main/java/org/opensearch/action/TaskOperationFailure.java index ea6f5508ab332..25e1ab1bb3d6f 100644 --- a/server/src/main/java/org/opensearch/action/TaskOperationFailure.java +++ b/server/src/main/java/org/opensearch/action/TaskOperationFailure.java @@ -32,7 +32,7 @@ package org.opensearch.action; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.core.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -90,7 +90,7 @@ public TaskOperationFailure(String nodeId, long taskId, Exception e) { this.nodeId = nodeId; this.taskId = taskId; this.reason = e; - status = BaseExceptionsHelper.status(e); + status = ExceptionsHelper.status(e); } /** @@ -144,7 +144,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (reason != null) { builder.field(REASON); builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, params, reason); + OpenSearchException.generateThrowableXContent(builder, params, reason); builder.endObject(); } return builder; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsResponse.java index 874f6c9f13ac7..f6d9a5c7b6453 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsResponse.java @@ -32,7 +32,7 @@ package org.opensearch.action.admin.cluster.node.reload; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.action.FailedNodeException; import org.opensearch.action.support.nodes.BaseNodeResponse; import org.opensearch.action.support.nodes.BaseNodesResponse; @@ -83,7 +83,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws final Exception e = node.reloadException(); if (e != null) { builder.startObject("reload_exception"); - BaseExceptionsHelper.generateThrowableXContent(builder, params, e); + OpenSearchException.generateThrowableXContent(builder, params, e); builder.endObject(); } builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java index 6d1525c6b671b..01321bb09323d 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java @@ -33,7 +33,7 @@ package org.opensearch.action.admin.indices.shards; import com.carrotsearch.hppc.cursors.IntObjectCursor; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.support.DefaultShardOperationFailedException; import org.opensearch.cluster.node.DiscoveryNode; @@ -202,7 +202,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(Fields.ALLOCATED, allocationStatus.value()); if (storeException != null) { builder.startObject(Fields.STORE_EXCEPTION); - BaseExceptionsHelper.generateThrowableXContent(builder, params, storeException); + OpenSearchException.generateThrowableXContent(builder, params, storeException); builder.endObject(); } return builder; diff --git a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java index f5e8967d81c53..c712a18e85013 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java @@ -32,7 +32,7 @@ package org.opensearch.action.bulk; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.DocWriteRequest.OpType; @@ -94,7 +94,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(_ID, failure.getId()); builder.field(STATUS, failure.getStatus().getStatus()); builder.startObject(ERROR); - BaseExceptionsHelper.generateThrowableXContent(builder, params, failure.getCause()); + OpenSearchException.generateThrowableXContent(builder, params, failure.getCause()); builder.endObject(); } builder.endObject(); @@ -218,7 +218,7 @@ public Failure(String index, String id, Exception cause) { index, id, cause, - BaseExceptionsHelper.status(cause), + ExceptionsHelper.status(cause), SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, false @@ -230,7 +230,7 @@ public Failure(String index, String id, Exception cause, boolean aborted) { index, id, cause, - BaseExceptionsHelper.status(cause), + ExceptionsHelper.status(cause), SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, aborted @@ -243,7 +243,7 @@ public Failure(String index, String id, Exception cause, RestStatus status) { /** For write failures after operation was assigned a sequence number. */ public Failure(String index, String id, Exception cause, long seqNo, long term) { - this(index, id, cause, BaseExceptionsHelper.status(cause), seqNo, term, false); + this(index, id, cause, ExceptionsHelper.status(cause), seqNo, term, false); } private Failure(String index, String id, Exception cause, RestStatus status, long seqNo, long term, boolean aborted) { @@ -268,7 +268,7 @@ public Failure(StreamInput in) throws IOException { } id = in.readOptionalString(); cause = in.readException(); - status = BaseExceptionsHelper.status(cause); + status = ExceptionsHelper.status(cause); seqNo = in.readZLong(); term = in.readVLong(); aborted = in.readBoolean(); @@ -356,7 +356,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(ID_FIELD, id); } builder.startObject(CAUSE_FIELD); - BaseExceptionsHelper.generateThrowableXContent(builder, params, cause); + OpenSearchException.generateThrowableXContent(builder, params, cause); builder.endObject(); builder.field(STATUS_FIELD, status.getStatus()); return builder; diff --git a/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java index fe9d0f21e01b2..ed407550b8b2f 100644 --- a/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java @@ -35,7 +35,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.SparseFixedBitSet; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.core.Assertions; import org.opensearch.OpenSearchParseException; import org.opensearch.ResourceAlreadyExistsException; @@ -325,7 +325,7 @@ protected void doRun() { @Override public void onFailure(Exception e) { - if (!(BaseExceptionsHelper.unwrapCause(e) instanceof ResourceAlreadyExistsException)) { + if (!(ExceptionsHelper.unwrapCause(e) instanceof ResourceAlreadyExistsException)) { // fail all requests involving this index, if create didn't work for (int i = 0; i < bulkRequest.requests.size(); i++) { DocWriteRequest request = bulkRequest.requests.get(i); diff --git a/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java b/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java index ff9226e5e6317..cbb30714ee8e1 100644 --- a/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java @@ -36,7 +36,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.MessageSupplier; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.ActionListenerResponseHandler; import org.opensearch.action.ActionRunnable; @@ -719,7 +719,7 @@ && isConflictException(executionResult.getFailure().getCause()) } private static boolean isConflictException(final Exception e) { - return BaseExceptionsHelper.unwrapCause(e) instanceof VersionConflictEngineException; + return ExceptionsHelper.unwrapCause(e) instanceof VersionConflictEngineException; } /** diff --git a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java index c00eb572b6ac4..b6c30b6be00c9 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java @@ -32,7 +32,7 @@ package org.opensearch.action.search; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.common.Nullable; @@ -192,7 +192,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); if (item.isFailure()) { OpenSearchException.generateFailureXContent(builder, params, item.getFailure(), true); - builder.field(Fields.STATUS, BaseExceptionsHelper.status(item.getFailure()).getStatus()); + builder.field(Fields.STATUS, ExceptionsHelper.status(item.getFailure()).getStatus()); } else { item.getResponse().innerToXContent(builder, params); builder.field(Fields.STATUS, item.getResponse().status().getStatus()); diff --git a/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java b/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java index aead19afc2942..65c876cbd7c61 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java +++ b/server/src/main/java/org/opensearch/action/search/SearchPhaseExecutionException.java @@ -32,7 +32,6 @@ package org.opensearch.action.search; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ShardOperationFailedException; @@ -100,7 +99,7 @@ public RestStatus status() { if (shardFailures.length == 0) { // if no successful shards, the failure can be due to OpenSearchRejectedExecutionException during fetch phase // on coordinator node. so get the status from cause instead of returning SERVICE_UNAVAILABLE blindly - return getCause() == null ? RestStatus.SERVICE_UNAVAILABLE : BaseExceptionsHelper.status(getCause()); + return getCause() == null ? RestStatus.SERVICE_UNAVAILABLE : ExceptionsHelper.status(getCause()); } RestStatus status = shardFailures[0].status(); if (shardFailures.length > 1) { @@ -160,14 +159,14 @@ protected void metadataToXContent(XContentBuilder builder, Params params) throws @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - Throwable ex = BaseExceptionsHelper.unwrapCause(this); + Throwable ex = ExceptionsHelper.unwrapCause(this); if (ex != this) { - BaseExceptionsHelper.generateThrowableXContent(builder, params, this); + OpenSearchException.generateThrowableXContent(builder, params, this); } else { // We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause // (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to // be rendered twice (one in the "cause" field, one in "failed_shards") - BaseExceptionsHelper.innerToXContent( + OpenSearchException.innerToXContent( builder, params, this, diff --git a/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java b/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java index aafdd553d4522..891f7f3119541 100644 --- a/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java +++ b/server/src/main/java/org/opensearch/action/search/ShardSearchFailure.java @@ -32,7 +32,7 @@ package org.opensearch.action.search; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.OriginalIndices; import org.opensearch.action.ShardOperationFailedException; @@ -85,15 +85,15 @@ public ShardSearchFailure(Exception e) { } public ShardSearchFailure(Exception e, @Nullable SearchShardTarget shardTarget) { - this(e, BaseExceptionsHelper.unwrapCause(e), shardTarget); + this(e, ExceptionsHelper.unwrapCause(e), shardTarget); } private ShardSearchFailure(final Exception e, final Throwable unwrappedCause, @Nullable SearchShardTarget shardTarget) { super( shardTarget == null ? null : shardTarget.getFullyQualifiedIndexName(), shardTarget == null ? -1 : shardTarget.getShardId().getId(), - BaseExceptionsHelper.detailedMessage(e), - BaseExceptionsHelper.status(unwrappedCause), + ExceptionsHelper.detailedMessage(e), + ExceptionsHelper.status(unwrappedCause), unwrappedCause ); @@ -119,7 +119,7 @@ public String toString() { + "], reason [" + reason + "], cause [" - + (cause == null ? "_na" : BaseExceptionsHelper.stackTrace(cause)) + + (cause == null ? "_na" : ExceptionsHelper.stackTrace(cause)) + "]"; } @@ -147,7 +147,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } builder.field(REASON_FIELD); builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, params, cause); + OpenSearchException.generateThrowableXContent(builder, params, cause); builder.endObject(); } builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/support/TransportActions.java b/server/src/main/java/org/opensearch/action/support/TransportActions.java index 62059ca3f0754..03e7509b3b8e3 100644 --- a/server/src/main/java/org/opensearch/action/support/TransportActions.java +++ b/server/src/main/java/org/opensearch/action/support/TransportActions.java @@ -33,7 +33,7 @@ package org.opensearch.action.support; import org.apache.lucene.store.AlreadyClosedException; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.NoShardAvailableActionException; import org.opensearch.action.UnavailableShardsException; import org.opensearch.index.IndexNotFoundException; @@ -48,7 +48,7 @@ public class TransportActions { public static boolean isShardNotAvailableException(final Throwable e) { - final Throwable actual = BaseExceptionsHelper.unwrapCause(e); + final Throwable actual = ExceptionsHelper.unwrapCause(e); return (actual instanceof ShardNotFoundException || actual instanceof IndexNotFoundException || actual instanceof IllegalIndexShardStateException diff --git a/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java b/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java index 968feca583d07..a7c7a799883a6 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java +++ b/server/src/main/java/org/opensearch/action/support/replication/ReplicationOperation.java @@ -34,7 +34,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.lucene.store.AlreadyClosedException; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.core.Assertions; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; @@ -284,7 +284,7 @@ public void onFailure(Exception replicaException) { // Only report "critical" exceptions // TODO: Reach out to the cluster-manager node to get the latest shard state then report. if (TransportActions.isShardNotAvailableException(replicaException) == false) { - RestStatus restStatus = BaseExceptionsHelper.status(replicaException); + RestStatus restStatus = ExceptionsHelper.status(replicaException); shardReplicaFailures.add( new ReplicationResponse.ShardInfo.Failure( shard.shardId(), @@ -333,7 +333,7 @@ public void onFinished() { @Override public boolean shouldRetry(Exception e) { - final Throwable cause = BaseExceptionsHelper.unwrapCause(e); + final Throwable cause = ExceptionsHelper.unwrapCause(e); return cause instanceof CircuitBreakingException || cause instanceof OpenSearchRejectedExecutionException || cause instanceof ConnectTransportException; @@ -358,7 +358,7 @@ private void updateCheckPoints(ShardRouting shard, LongSupplier localCheckpointS } private void onNoLongerPrimary(Exception failure) { - final Throwable cause = BaseExceptionsHelper.unwrapCause(failure); + final Throwable cause = ExceptionsHelper.unwrapCause(failure); final boolean nodeIsClosing = cause instanceof NodeClosedException; final String message; if (nodeIsClosing) { diff --git a/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java b/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java index 1b3b72d45b5b5..6f8f93ccc0ce3 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java +++ b/server/src/main/java/org/opensearch/action/support/replication/ReplicationResponse.java @@ -32,7 +32,7 @@ package org.opensearch.action.support.replication; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.ShardOperationFailedException; @@ -261,7 +261,7 @@ public Failure(StreamInput in) throws IOException { } public Failure(ShardId shardId, @Nullable String nodeId, Exception cause, RestStatus status, boolean primary) { - super(shardId.getIndexName(), shardId.getId(), BaseExceptionsHelper.detailedMessage(cause), status, cause); + super(shardId.getIndexName(), shardId.getId(), ExceptionsHelper.detailedMessage(cause), status, cause); this.shardId = shardId; this.nodeId = nodeId; this.primary = primary; @@ -304,7 +304,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(_NODE, nodeId); builder.field(REASON); builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, params, cause); + OpenSearchException.generateThrowableXContent(builder, params, cause); builder.endObject(); builder.field(STATUS, status); builder.field(PRIMARY, primary); diff --git a/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java b/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java index e85b77eba0416..b4bacefad8ad2 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java +++ b/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java @@ -33,7 +33,7 @@ package org.opensearch.action.support.replication; import com.carrotsearch.hppc.cursors.IntObjectCursor; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.DefaultShardOperationFailedException; @@ -122,7 +122,7 @@ public void onFailure(Exception e) { shardId, null, e, - BaseExceptionsHelper.status(e), + ExceptionsHelper.status(e), true ); failures = new ReplicationResponse.ShardInfo.Failure[totalNumCopies]; diff --git a/server/src/main/java/org/opensearch/cluster/action/shard/ShardStateAction.java b/server/src/main/java/org/opensearch/cluster/action/shard/ShardStateAction.java index 853690fa1e242..002c5fd3b89db 100644 --- a/server/src/main/java/org/opensearch/cluster/action/shard/ShardStateAction.java +++ b/server/src/main/java/org/opensearch/cluster/action/shard/ShardStateAction.java @@ -35,7 +35,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; @@ -630,7 +629,7 @@ public String toString() { components.add("primary term [" + primaryTerm + "]"); components.add("message [" + message + "]"); if (failure != null) { - components.add("failure [" + BaseExceptionsHelper.detailedMessage(failure) + "]"); + components.add("failure [" + ExceptionsHelper.detailedMessage(failure) + "]"); } components.add("markAsStale [" + markAsStale + "]"); return String.join(", ", components); diff --git a/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java b/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java index 4e48441c7a39a..45fdf7ca641de 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java +++ b/server/src/main/java/org/opensearch/cluster/routing/UnassignedInfo.java @@ -32,7 +32,7 @@ package org.opensearch.cluster.routing; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.routing.allocation.RoutingAllocation; @@ -390,7 +390,7 @@ public String getDetails() { if (message == null) { return null; } - return message + (failure == null ? "" : ", failure " + BaseExceptionsHelper.detailedMessage(failure)); + return message + (failure == null ? "" : ", failure " + ExceptionsHelper.detailedMessage(failure)); } /** diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/FailedShard.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/FailedShard.java index d08dbba3a249d..61ca0f50e93b9 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/FailedShard.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/FailedShard.java @@ -32,7 +32,7 @@ package org.opensearch.cluster.routing.allocation; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.common.Nullable; @@ -62,7 +62,7 @@ public String toString() { + ", message [" + message + "], failure [" - + (failure == null ? "null" : BaseExceptionsHelper.detailedMessage(failure)) + + (failure == null ? "null" : ExceptionsHelper.detailedMessage(failure)) + "], markAsStale [" + markAsStale + "]"; diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/NodeAllocationResult.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/NodeAllocationResult.java index ab1d56cbf7a9e..d50a474838a6b 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/NodeAllocationResult.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/NodeAllocationResult.java @@ -32,7 +32,7 @@ package org.opensearch.cluster.routing.allocation; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.routing.allocation.decider.Decision; import org.opensearch.common.Nullable; @@ -300,7 +300,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } if (storeException != null) { builder.startObject("store_exception"); - BaseExceptionsHelper.generateThrowableXContent(builder, params, storeException); + OpenSearchException.generateThrowableXContent(builder, params, storeException); builder.endObject(); } } diff --git a/server/src/main/java/org/opensearch/common/Strings.java b/server/src/main/java/org/opensearch/common/Strings.java index 0bec840a15f40..15a4b17252450 100644 --- a/server/src/main/java/org/opensearch/common/Strings.java +++ b/server/src/main/java/org/opensearch/common/Strings.java @@ -33,7 +33,7 @@ package org.opensearch.common; import org.apache.lucene.util.BytesRefBuilder; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.util.CollectionUtils; @@ -280,7 +280,7 @@ private static String toString(MediaType mediaType, ToXContent toXContent, ToXCo XContentBuilder builder = createBuilder(mediaType, pretty, human); builder.startObject(); builder.field("error", "error building toString out of XContent: " + e.getMessage()); - builder.field("stack_trace", BaseExceptionsHelper.stackTrace(e)); + builder.field("stack_trace", ExceptionsHelper.stackTrace(e)); builder.endObject(); return toString(builder); } catch (IOException e2) { diff --git a/server/src/main/java/org/opensearch/common/lucene/search/Queries.java b/server/src/main/java/org/opensearch/common/lucene/search/Queries.java index 13a9551d9e421..125eab9512be8 100644 --- a/server/src/main/java/org/opensearch/common/lucene/search/Queries.java +++ b/server/src/main/java/org/opensearch/common/lucene/search/Queries.java @@ -47,7 +47,7 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.common.Nullable; import org.opensearch.index.mapper.SeqNoFieldMapper; @@ -83,7 +83,7 @@ public static Query newUnmappedFieldsQuery(Collection fields) { } public static Query newLenientFieldQuery(String field, RuntimeException e) { - String message = BaseExceptionsHelper.getExceptionName(e) + ":[" + e.getMessage() + "]"; + String message = OpenSearchException.getExceptionName(e) + ":[" + e.getMessage() + "]"; return Queries.newMatchNoDocsQuery("failed [" + field + "] query, caused by " + message); } diff --git a/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java b/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java index 35272d9f54dc6..e4df2e604c320 100644 --- a/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java +++ b/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java @@ -33,7 +33,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.action.ActionListener; import org.opensearch.action.FailedNodeException; @@ -251,7 +251,7 @@ protected synchronized void processAsyncFetch(List responses, List searchLookup) { throw new IllegalArgumentException("Fielddata is not supported on field [" + name() + "] of type [" + typeName() + "]"); @@ -412,7 +412,7 @@ public Relation isFieldWithinQuery( /** @throws IllegalArgumentException if the fielddata is not supported on this type. * An IllegalArgumentException is needed in order to return an http error 400 - * when this error occurs in a request. see: {@link BaseExceptionsHelper#status} + * when this error occurs in a request. see: {@link ExceptionsHelper#status} **/ protected final void failIfNoDocValues() { if (hasDocValues() == false) { diff --git a/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java index cc5cae168e7b6..ab711d3a0ea00 100644 --- a/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/MoreLikeThisQueryBuilder.java @@ -37,7 +37,6 @@ import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchParseException; import org.opensearch.ExceptionsHelper; import org.opensearch.Version; @@ -449,7 +448,7 @@ public String toString() { toXContent(builder, EMPTY_PARAMS); return Strings.toString(builder); } catch (Exception e) { - return "{ \"error\" : \"" + BaseExceptionsHelper.detailedMessage(e) + "\"}"; + return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}"; } } diff --git a/server/src/main/java/org/opensearch/index/reindex/BulkByScrollTask.java b/server/src/main/java/org/opensearch/index/reindex/BulkByScrollTask.java index be9cade4925eb..2fe0fe0259c33 100644 --- a/server/src/main/java/org/opensearch/index/reindex/BulkByScrollTask.java +++ b/server/src/main/java/org/opensearch/index/reindex/BulkByScrollTask.java @@ -32,7 +32,6 @@ package org.opensearch.index.reindex; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.common.Nullable; import org.opensearch.core.ParseField; @@ -1000,7 +999,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws status.toXContent(builder, params); } else { builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, params, exception); + OpenSearchException.generateThrowableXContent(builder, params, exception); builder.endObject(); } return builder; diff --git a/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java b/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java index 78a3835cf7b33..81560de78b336 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java +++ b/server/src/main/java/org/opensearch/index/reindex/ScrollableHitSource.java @@ -33,7 +33,8 @@ package org.opensearch.index.reindex; import org.apache.logging.log4j.Logger; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.bulk.BackoffPolicy; import org.opensearch.action.bulk.BulkItemResponse; @@ -408,7 +409,7 @@ public static class SearchFailure implements Writeable, ToXContentObject { public static final String STATUS_FIELD = BulkItemResponse.Failure.STATUS_FIELD; public SearchFailure(Throwable reason, @Nullable String index, @Nullable Integer shardId, @Nullable String nodeId) { - this(reason, index, shardId, nodeId, BaseExceptionsHelper.status(reason)); + this(reason, index, shardId, nodeId, ExceptionsHelper.status(reason)); } public SearchFailure( @@ -440,7 +441,7 @@ public SearchFailure(StreamInput in) throws IOException { index = in.readOptionalString(); shardId = in.readOptionalVInt(); nodeId = in.readOptionalString(); - status = BaseExceptionsHelper.status(reason); + status = ExceptionsHelper.status(reason); } @Override @@ -488,7 +489,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(REASON_FIELD); { builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, params, reason); + OpenSearchException.generateThrowableXContent(builder, params, reason); builder.endObject(); } builder.endObject(); diff --git a/server/src/main/java/org/opensearch/index/shard/IndexShard.java b/server/src/main/java/org/opensearch/index/shard/IndexShard.java index ec6d8a7b73c99..e368ee82b1084 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -57,7 +57,6 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ThreadInterruptedException; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.common.lucene.store.ByteArrayIndexInput; import org.opensearch.cluster.metadata.DataStream; import org.opensearch.core.Assertions; @@ -2213,7 +2212,7 @@ int runTranslogRecovery(Engine engine, Translog.Snapshot snapshot, Engine.Operat onOperationRecovered.run(); } catch (Exception e) { // TODO: Don't enable this leniency unless users explicitly opt-in - if (origin == Engine.Operation.Origin.LOCAL_TRANSLOG_RECOVERY && BaseExceptionsHelper.status(e) == RestStatus.BAD_REQUEST) { + if (origin == Engine.Operation.Origin.LOCAL_TRANSLOG_RECOVERY && ExceptionsHelper.status(e) == RestStatus.BAD_REQUEST) { // mainly for MapperParsingException and Failure to detect xcontent logger.info("ignoring recovery of a corrupt translog entry", e); } else { diff --git a/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java b/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java index 02397bc356539..a81dc96ff1145 100644 --- a/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java +++ b/server/src/main/java/org/opensearch/index/shard/StoreRecovery.java @@ -42,7 +42,7 @@ import org.apache.lucene.store.FilterDirectory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.cluster.metadata.IndexMetadata; @@ -500,7 +500,7 @@ private void internalRecoverFromStore(IndexShard indexShard) throws IndexShardRe files = Arrays.toString(store.directory().listAll()); } catch (Exception inner) { inner.addSuppressed(e); - files += " (failure=" + BaseExceptionsHelper.detailedMessage(inner) + ")"; + files += " (failure=" + ExceptionsHelper.detailedMessage(inner) + ")"; } if (indexShouldExists) { throw new IndexShardRecoveryException( diff --git a/server/src/main/java/org/opensearch/indices/recovery/PeerRecoveryTargetService.java b/server/src/main/java/org/opensearch/indices/recovery/PeerRecoveryTargetService.java index a08d3182fa156..17af529a700d9 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/PeerRecoveryTargetService.java +++ b/server/src/main/java/org/opensearch/indices/recovery/PeerRecoveryTargetService.java @@ -36,7 +36,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.lucene.store.AlreadyClosedException; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.action.ActionListener; @@ -679,7 +679,7 @@ private void onException(Exception e) { e ); } - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause instanceof CancellableThreads.ExecutionCancelledException) { // this can also come from the source wrapped in a RemoteTransportException onGoingRecoveries.fail(recoveryId, new RecoveryFailedException(request, "source has canceled the recovery", cause), false); @@ -690,7 +690,7 @@ private void onException(Exception e) { cause = cause.getCause(); } // do it twice, in case we have double transport exception - cause = BaseExceptionsHelper.unwrapCause(cause); + cause = ExceptionsHelper.unwrapCause(cause); if (cause instanceof RecoveryEngineException) { // unwrap an exception that was thrown as part of the recovery cause = cause.getCause(); diff --git a/server/src/main/java/org/opensearch/indices/recovery/RetryableTransportClient.java b/server/src/main/java/org/opensearch/indices/recovery/RetryableTransportClient.java index f7d75b356d6a3..77ffd75d0148a 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/RetryableTransportClient.java +++ b/server/src/main/java/org/opensearch/indices/recovery/RetryableTransportClient.java @@ -9,7 +9,7 @@ package org.opensearch.indices.recovery; import org.apache.logging.log4j.Logger; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.ActionListenerResponseHandler; import org.opensearch.action.support.RetryableAction; @@ -127,10 +127,10 @@ private static boolean retryableException(Exception e) { if (e instanceof ConnectTransportException) { return true; } else if (e instanceof SendRequestTransportException) { - final Throwable cause = BaseExceptionsHelper.unwrapCause(e); + final Throwable cause = ExceptionsHelper.unwrapCause(e); return cause instanceof ConnectTransportException; } else if (e instanceof RemoteTransportException) { - final Throwable cause = BaseExceptionsHelper.unwrapCause(e); + final Throwable cause = ExceptionsHelper.unwrapCause(e); return cause instanceof CircuitBreakingException || cause instanceof OpenSearchRejectedExecutionException; } return false; diff --git a/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTargetService.java b/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTargetService.java index 2931caa353bc6..a7e0c0ec887ab 100644 --- a/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTargetService.java +++ b/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTargetService.java @@ -11,7 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.routing.ShardRouting; @@ -444,7 +444,7 @@ public void onResponse(Void o) { @Override public void onFailure(Exception e) { - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause instanceof CancellableThreads.ExecutionCancelledException) { if (onGoingReplications.getTarget(replicationId) != null) { IndexShard indexShard = onGoingReplications.getTarget(replicationId).indexShard(); diff --git a/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java b/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java index 415fb91874416..4d75ff4896706 100644 --- a/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java +++ b/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java @@ -10,7 +10,7 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.store.RateLimiter; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.support.ChannelActionListener; @@ -176,7 +176,7 @@ public void fail(ReplicationFailedException e, boolean sendShardFailure) { notifyListener(e, sendShardFailure); } finally { try { - cancellableThreads.cancel("failed" + description() + "[" + BaseExceptionsHelper.stackTrace(e) + "]"); + cancellableThreads.cancel("failed" + description() + "[" + ExceptionsHelper.stackTrace(e) + "]"); } finally { // release the initial reference. replication files will be cleaned as soon as ref count goes to zero, potentially now decRef(); diff --git a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java index 4533b2ca9d703..3bb094bcd4ba0 100644 --- a/server/src/main/java/org/opensearch/rest/BytesRestResponse.java +++ b/server/src/main/java/org/opensearch/rest/BytesRestResponse.java @@ -36,7 +36,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchStatusException; import org.opensearch.common.bytes.BytesArray; @@ -105,14 +105,14 @@ public BytesRestResponse(RestStatus status, String contentType, BytesReference c } public BytesRestResponse(RestChannel channel, Exception e) throws IOException { - this(channel, BaseExceptionsHelper.status(e), e); + this(channel, ExceptionsHelper.status(e), e); } public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) throws IOException { ToXContent.Params params = paramsFromRequest(channel.request()); if (params.paramAsBoolean( - BaseExceptionsHelper.REST_EXCEPTION_SKIP_STACK_TRACE, - BaseExceptionsHelper.REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT + OpenSearchException.REST_EXCEPTION_SKIP_STACK_TRACE, + OpenSearchException.REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT ) && e != null) { // log exception only if it is not returned in the response Supplier messageSupplier = () -> new ParameterizedMessage( @@ -154,12 +154,9 @@ public RestStatus status() { private ToXContent.Params paramsFromRequest(RestRequest restRequest) { ToXContent.Params params = restRequest; - if (params.paramAsBoolean("error_trace", !BaseExceptionsHelper.REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT) + if (params.paramAsBoolean("error_trace", OpenSearchException.REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT == false) && false == skipStackTrace()) { - params = new ToXContent.DelegatingMapParams( - singletonMap(BaseExceptionsHelper.REST_EXCEPTION_SKIP_STACK_TRACE, "false"), - params - ); + params = new ToXContent.DelegatingMapParams(singletonMap(OpenSearchException.REST_EXCEPTION_SKIP_STACK_TRACE, "false"), params); } return params; } diff --git a/server/src/main/java/org/opensearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java b/server/src/main/java/org/opensearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java index dc75088d4c85b..afd46f1a8164c 100644 --- a/server/src/main/java/org/opensearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java +++ b/server/src/main/java/org/opensearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java @@ -40,7 +40,7 @@ import org.apache.lucene.search.spell.StringDistance; import org.apache.lucene.search.spell.SuggestMode; import org.apache.lucene.util.automaton.LevenshteinAutomata; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.core.ParseField; import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; @@ -510,7 +510,7 @@ public String toString() { toXContent(builder, EMPTY_PARAMS); return Strings.toString(builder); } catch (Exception e) { - return "{ \"error\" : \"" + BaseExceptionsHelper.detailedMessage(e) + "\"}"; + return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}"; } } diff --git a/server/src/main/java/org/opensearch/tasks/TaskCancellationService.java b/server/src/main/java/org/opensearch/tasks/TaskCancellationService.java index 4368b5fe0ba3a..ebce26c4bbfbc 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskCancellationService.java +++ b/server/src/main/java/org/opensearch/tasks/TaskCancellationService.java @@ -34,7 +34,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchSecurityException; import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; @@ -156,7 +156,7 @@ public void handleResponse(TransportResponse.Empty response) { @Override public void handleException(TransportException exp) { - assert BaseExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false; + assert ExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false; logger.warn("Cannot send ban for tasks with the parent [{}] to the node [{}]", taskId, node); groupedListener.onFailure(exp); } @@ -172,7 +172,7 @@ private void removeBanOnNodes(CancellableTask task, Collection ch transportService.sendRequest(node, BAN_PARENT_ACTION_NAME, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) { @Override public void handleException(TransportException exp) { - assert BaseExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false; + assert ExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false; logger.info("failed to remove the parent ban for task {} on node {}", request.parentTaskId, node); } }); diff --git a/server/src/main/java/org/opensearch/tasks/TaskManager.java b/server/src/main/java/org/opensearch/tasks/TaskManager.java index 443a6c0853884..f243cf392bbb8 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskManager.java +++ b/server/src/main/java/org/opensearch/tasks/TaskManager.java @@ -37,7 +37,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.core.Assertions; import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; @@ -370,7 +369,7 @@ public void storeResult(Task task, Exception e try { taskResult = task.result(localNode, error); } catch (IOException ex) { - logger.warn(() -> new ParameterizedMessage("couldn't store error {}", BaseExceptionsHelper.detailedMessage(error)), ex); + logger.warn(() -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), ex); listener.onFailure(ex); return; } @@ -382,7 +381,7 @@ public void onResponse(Void aVoid) { @Override public void onFailure(Exception e) { - logger.warn(() -> new ParameterizedMessage("couldn't store error {}", BaseExceptionsHelper.detailedMessage(error)), e); + logger.warn(() -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), e); listener.onFailure(e); } }); diff --git a/server/src/main/java/org/opensearch/tasks/TaskResult.java b/server/src/main/java/org/opensearch/tasks/TaskResult.java index 11ea9a9a82861..2387de173c924 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskResult.java +++ b/server/src/main/java/org/opensearch/tasks/TaskResult.java @@ -31,7 +31,7 @@ package org.opensearch.tasks; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.OpenSearchException; import org.opensearch.client.Requests; import org.opensearch.common.Nullable; import org.opensearch.core.ParseField; @@ -240,7 +240,7 @@ public int hashCode() { private static BytesReference toXContent(Exception error) throws IOException { try (XContentBuilder builder = XContentFactory.contentBuilder(Requests.INDEX_CONTENT_TYPE)) { builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, ToXContent.EMPTY_PARAMS, error); + OpenSearchException.generateThrowableXContent(builder, ToXContent.EMPTY_PARAMS, error); builder.endObject(); return BytesReference.bytes(builder); } diff --git a/server/src/main/java/org/opensearch/tasks/TaskResultsService.java b/server/src/main/java/org/opensearch/tasks/TaskResultsService.java index 329fc55431bc8..1feb115cb585a 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskResultsService.java +++ b/server/src/main/java/org/opensearch/tasks/TaskResultsService.java @@ -34,7 +34,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.ResourceAlreadyExistsException; import org.opensearch.action.ActionListener; @@ -126,7 +126,7 @@ public void onResponse(CreateIndexResponse result) { @Override public void onFailure(Exception e) { - if (BaseExceptionsHelper.unwrapCause(e) instanceof ResourceAlreadyExistsException) { + if (ExceptionsHelper.unwrapCause(e) instanceof ResourceAlreadyExistsException) { // we have the index, do it try { doStoreResult(taskResult, listener); diff --git a/server/src/test/java/org/opensearch/ExceptionsHelperTests.java b/server/src/test/java/org/opensearch/ExceptionsHelperTests.java index 2761d59958a84..4c65eadf46e89 100644 --- a/server/src/test/java/org/opensearch/ExceptionsHelperTests.java +++ b/server/src/test/java/org/opensearch/ExceptionsHelperTests.java @@ -108,18 +108,15 @@ private void assertError(final Throwable cause, final Error error) { } public void testStatus() { - assertThat(BaseExceptionsHelper.status(new IllegalArgumentException("illegal")), equalTo(RestStatus.BAD_REQUEST)); - assertThat(BaseExceptionsHelper.status(new JsonParseException(null, "illegal")), equalTo(RestStatus.BAD_REQUEST)); - assertThat( - BaseExceptionsHelper.status(new OpenSearchRejectedExecutionException("rejected")), - equalTo(RestStatus.TOO_MANY_REQUESTS) - ); + assertThat(ExceptionsHelper.status(new IllegalArgumentException("illegal")), equalTo(RestStatus.BAD_REQUEST)); + assertThat(ExceptionsHelper.status(new JsonParseException(null, "illegal")), equalTo(RestStatus.BAD_REQUEST)); + assertThat(ExceptionsHelper.status(new OpenSearchRejectedExecutionException("rejected")), equalTo(RestStatus.TOO_MANY_REQUESTS)); } public void testSummaryMessage() { - assertThat(BaseExceptionsHelper.summaryMessage(new IllegalArgumentException("illegal")), equalTo("Invalid argument")); - assertThat(BaseExceptionsHelper.summaryMessage(new JsonParseException(null, "illegal")), equalTo("Failed to parse JSON")); - assertThat(BaseExceptionsHelper.summaryMessage(new OpenSearchRejectedExecutionException("rejected")), equalTo("Too many requests")); + assertThat(ExceptionsHelper.summaryMessage(new IllegalArgumentException("illegal")), equalTo("Invalid argument")); + assertThat(ExceptionsHelper.summaryMessage(new JsonParseException(null, "illegal")), equalTo("Failed to parse JSON")); + assertThat(ExceptionsHelper.summaryMessage(new OpenSearchRejectedExecutionException("rejected")), equalTo("Too many requests")); } public void testGroupBy() { diff --git a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java index 08fd4d581f587..a0bd8202abbbe 100644 --- a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java +++ b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java @@ -129,7 +129,7 @@ public void testGuessRootCause() { ); OpenSearchException[] rootCauses = exception.guessRootCauses(); assertEquals(rootCauses.length, 1); - assertEquals(BaseExceptionsHelper.getExceptionName(rootCauses[0]), "index_not_found_exception"); + assertEquals(OpenSearchException.getExceptionName(rootCauses[0]), "index_not_found_exception"); assertEquals("no such index [foo]", rootCauses[0].getMessage()); ShardSearchFailure failure = new ShardSearchFailure( new ParsingException(1, 2, "foobar", null), @@ -149,12 +149,12 @@ public void testGuessRootCause() { } else { rootCauses = OpenSearchException.guessRootCauses(randomBoolean() ? new RemoteTransportException("remoteboom", ex) : ex); } - assertEquals("parsing_exception", BaseExceptionsHelper.getExceptionName(rootCauses[0])); + assertEquals("parsing_exception", OpenSearchException.getExceptionName(rootCauses[0])); assertEquals("foobar", rootCauses[0].getMessage()); OpenSearchException oneLevel = new OpenSearchException("foo", new RuntimeException("foobar")); rootCauses = oneLevel.guessRootCauses(); - assertEquals("exception", BaseExceptionsHelper.getExceptionName(rootCauses[0])); + assertEquals("exception", OpenSearchException.getExceptionName(rootCauses[0])); assertEquals("foo", rootCauses[0].getMessage()); } { @@ -177,12 +177,12 @@ public void testGuessRootCause() { ); final OpenSearchException[] rootCauses = ex.guessRootCauses(); assertEquals(rootCauses.length, 2); - assertEquals(BaseExceptionsHelper.getExceptionName(rootCauses[0]), "parsing_exception"); + assertEquals(OpenSearchException.getExceptionName(rootCauses[0]), "parsing_exception"); assertEquals(rootCauses[0].getMessage(), "foobar"); assertEquals(1, ((ParsingException) rootCauses[0]).getLineNumber()); assertEquals(2, ((ParsingException) rootCauses[0]).getColumnNumber()); - assertEquals("query_shard_exception", BaseExceptionsHelper.getExceptionName(rootCauses[1])); - assertEquals("foo1", rootCauses[1].getIndexName()); + assertEquals("query_shard_exception", OpenSearchException.getExceptionName(rootCauses[1])); + assertEquals("foo1", rootCauses[1].getIndex().getName()); assertEquals("foobar", rootCauses[1].getMessage()); } @@ -409,7 +409,7 @@ public void testToXContent() throws IOException { // Test the same exception but with the "rest.exception.stacktrace.skip" parameter disabled: the stack_trace must be present // in the JSON. Since the stack can be large, it only checks the beginning of the JSON. ToXContent.Params params = new ToXContent.MapParams( - Collections.singletonMap(BaseExceptionsHelper.REST_EXCEPTION_SKIP_STACK_TRACE, "false") + Collections.singletonMap(OpenSearchException.REST_EXCEPTION_SKIP_STACK_TRACE, "false") ); String actual; try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { @@ -451,7 +451,7 @@ public void testGenerateThrowableToXContent() throws IOException { OpenSearchException ex = new RemoteTransportException("foobar", new FileNotFoundException("foo not found")); String toXContentString = Strings.toString(XContentType.JSON, ex); String throwableString = Strings.toString(XContentType.JSON, (builder, params) -> { - BaseExceptionsHelper.generateThrowableXContent(builder, params, ex); + OpenSearchException.generateThrowableXContent(builder, params, ex); return builder; }); @@ -740,7 +740,7 @@ public void testThrowableToAndFromXContent() throws IOException { } BytesReference throwableBytes = toShuffledXContent((builder, params) -> { - BaseExceptionsHelper.generateThrowableXContent(builder, params, throwable); + OpenSearchException.generateThrowableXContent(builder, params, throwable); return builder; }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); @@ -756,7 +756,7 @@ public void testThrowableToAndFromXContent() throws IOException { if (suppressedCount > 0) { XContentBuilder builder = XContentBuilder.builder(xContent); builder.startObject(); - BaseExceptionsHelper.generateThrowableXContent(builder, ToXContent.EMPTY_PARAMS, throwable); + OpenSearchException.generateThrowableXContent(builder, ToXContent.EMPTY_PARAMS, throwable); builder.endObject(); throwableBytes = BytesReference.bytes(builder); try (XContentParser parser = createParser(xContent, throwableBytes)) { @@ -814,7 +814,7 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException { } assertNotNull(parsedFailure); - String reason = BaseExceptionsHelper.summaryMessage(failure); + String reason = ExceptionsHelper.summaryMessage(failure); assertEquals(OpenSearchException.buildMessage("exception", reason, null), parsedFailure.getMessage()); assertEquals(0, parsedFailure.getHeaders().size()); assertEquals(0, parsedFailure.getMetadata().size()); @@ -983,7 +983,7 @@ private static void assertToXContentAsJson(ToXContent e, String expectedJson) th private static void assertExceptionAsJson(Exception e, String expectedJson) throws IOException { assertToXContentAsJson((builder, params) -> { - BaseExceptionsHelper.generateThrowableXContent(builder, params, e); + OpenSearchException.generateThrowableXContent(builder, params, e); return builder; }, expectedJson); } diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java index f71d57f68a406..3e5a7d5ad5242 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkItemResponseTests.java @@ -32,7 +32,7 @@ package org.opensearch.action.bulk; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.DocWriteResponse; @@ -109,7 +109,7 @@ public void testFailureToAndFromXContent() throws IOException { Exception bulkItemCause = (Exception) exceptions.v1(); Failure bulkItemFailure = new Failure(index, id, bulkItemCause); BulkItemResponse bulkItemResponse = new BulkItemResponse(itemId, opType, bulkItemFailure); - Failure expectedBulkItemFailure = new Failure(index, id, exceptions.v2(), BaseExceptionsHelper.status(bulkItemCause)); + Failure expectedBulkItemFailure = new Failure(index, id, exceptions.v2(), ExceptionsHelper.status(bulkItemCause)); BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(itemId, opType, expectedBulkItemFailure); BytesReference originalBytes = toShuffledXContent(bulkItemResponse, xContentType, ToXContent.EMPTY_PARAMS, randomBoolean()); diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java index f7fd434b2fb26..aca2419e2d325 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkResponseTests.java @@ -32,7 +32,7 @@ package org.opensearch.action.bulk; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.DocWriteResponse; @@ -95,7 +95,7 @@ public void testToAndFromXContent() throws IOException { expectedBulkItems[i] = new BulkItemResponse( i, opType, - new BulkItemResponse.Failure(index, id, failures.v2(), BaseExceptionsHelper.status(bulkItemCause)) + new BulkItemResponse.Failure(index, id, failures.v2(), ExceptionsHelper.status(bulkItemCause)) ); } } diff --git a/server/src/test/java/org/opensearch/client/AbstractClientHeadersTestCase.java b/server/src/test/java/org/opensearch/client/AbstractClientHeadersTestCase.java index f40227beb59b7..92a88aa7940ee 100644 --- a/server/src/test/java/org/opensearch/client/AbstractClientHeadersTestCase.java +++ b/server/src/test/java/org/opensearch/client/AbstractClientHeadersTestCase.java @@ -32,7 +32,7 @@ package org.opensearch.client; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionType; import org.opensearch.action.ActionListener; import org.opensearch.action.admin.cluster.reroute.ClusterRerouteAction; @@ -244,7 +244,7 @@ public Throwable unwrap(Throwable t, Class exceptionType) { } if (counter++ > 10) { // dear god, if we got more than 10 levels down, WTF? just bail - fail("Exception cause unwrapping ran for 10 levels: " + BaseExceptionsHelper.stackTrace(t)); + fail("Exception cause unwrapping ran for 10 levels: " + ExceptionsHelper.stackTrace(t)); return null; } result = result.getCause(); diff --git a/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java b/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java index ae6352a6c6636..a5d70886aa651 100644 --- a/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java +++ b/server/src/test/java/org/opensearch/rest/BytesRestResponseTests.java @@ -32,7 +32,7 @@ package org.opensearch.rest; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchStatusException; import org.opensearch.OpenSearchException; import org.opensearch.ResourceAlreadyExistsException; @@ -183,7 +183,7 @@ public void testConvert() throws IOException { + "\"failed_shards\":[{\"shard\":1,\"index\":\"foo\",\"node\":\"node_1\",\"reason\":{\"type\":\"parsing_exception\"," + "\"reason\":\"foobar\",\"line\":1,\"col\":2}}]},\"status\":400}"; assertEquals(expected.trim(), text.trim()); - String stackTrace = BaseExceptionsHelper.stackTrace(ex); + String stackTrace = ExceptionsHelper.stackTrace(ex); assertTrue(stackTrace.contains("Caused by: ParsingException[foobar]")); } diff --git a/server/src/test/java/org/opensearch/search/aggregations/pipeline/DerivativeAggregatorTests.java b/server/src/test/java/org/opensearch/search/aggregations/pipeline/DerivativeAggregatorTests.java index 801f057d8888d..88628cd44c721 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/pipeline/DerivativeAggregatorTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/pipeline/DerivativeAggregatorTests.java @@ -41,7 +41,7 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.store.Directory; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.action.search.SearchPhaseExecutionException; import org.opensearch.common.CheckedConsumer; import org.opensearch.index.mapper.DateFieldMapper; @@ -635,7 +635,7 @@ public void testSingleValueAggDerivative_invalidPath() throws IOException { executeTestCase(query, aggBuilder, history -> {}); fail("Expected an Exception but didn't get one"); } catch (Exception e) { - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause == null) { throw e; } else if (cause instanceof SearchPhaseExecutionException) { diff --git a/server/src/test/java/org/opensearch/transport/TransportActionProxyTests.java b/server/src/test/java/org/opensearch/transport/TransportActionProxyTests.java index 64125863c3c5f..5190495a6253e 100644 --- a/server/src/test/java/org/opensearch/transport/TransportActionProxyTests.java +++ b/server/src/test/java/org/opensearch/transport/TransportActionProxyTests.java @@ -31,7 +31,7 @@ package org.opensearch.transport; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.cluster.node.DiscoveryNode; @@ -196,7 +196,7 @@ public void handleResponse(SimpleTestResponse response) { @Override public void handleException(TransportException exp) { try { - Throwable cause = BaseExceptionsHelper.unwrapCause(exp); + Throwable cause = ExceptionsHelper.unwrapCause(exp); assertEquals("greetings from TS_C", cause.getMessage()); } finally { latch.countDown(); diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java index 4474aae1f0631..caa5b90016740 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java @@ -41,7 +41,7 @@ import org.apache.lucene.search.Sort; import org.apache.lucene.search.TotalHits; import org.apache.lucene.tests.util.LuceneTestCase; -import org.opensearch.BaseExceptionsHelper; +import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.DocWriteResponse; @@ -1611,7 +1611,7 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma } final List actualErrors = new ArrayList<>(); for (Tuple tuple : errors) { - Throwable t = BaseExceptionsHelper.unwrapCause(tuple.v2()); + Throwable t = ExceptionsHelper.unwrapCause(tuple.v2()); if (t instanceof OpenSearchRejectedExecutionException) { logger.debug("Error indexing doc: " + t.getMessage() + ", reindexing."); tuple.v1().execute().actionGet(); // re-index if rejected diff --git a/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java b/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java index 0b1e119494a77..e52a6b48e219d 100644 --- a/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java +++ b/test/framework/src/main/java/org/opensearch/test/hamcrest/OpenSearchAssertions.java @@ -34,7 +34,6 @@ import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TotalHits; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionFuture; @@ -627,7 +626,7 @@ public static void assertFutureThrows( } if (status != null) { - assertThat(extraInfo, BaseExceptionsHelper.status(expected), equalTo(status)); + assertThat(extraInfo, ExceptionsHelper.status(expected), equalTo(status)); } } @@ -648,7 +647,7 @@ public static void assertFutureThrows(ActionFuture future, RestStatus status, extraInfo += "expected a " + status + " status exception to be thrown"; Exception e = expectThrows(Exception.class, future::actionGet); - assertThat(extraInfo, BaseExceptionsHelper.status(e), equalTo(status)); + assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status)); } /** diff --git a/test/framework/src/main/java/org/opensearch/transport/AbstractSimpleTransportTestCase.java b/test/framework/src/main/java/org/opensearch/transport/AbstractSimpleTransportTestCase.java index 94e66a34d6cea..fed14d6bbc1ba 100644 --- a/test/framework/src/main/java/org/opensearch/transport/AbstractSimpleTransportTestCase.java +++ b/test/framework/src/main/java/org/opensearch/transport/AbstractSimpleTransportTestCase.java @@ -39,7 +39,6 @@ import org.apache.logging.log4j.util.Supplier; import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.Constants; -import org.opensearch.BaseExceptionsHelper; import org.opensearch.LegacyESVersion; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; @@ -558,7 +557,7 @@ public void onRequestSent( serviceA.submitRequest(nodeB, ACTION, TransportRequest.Empty.INSTANCE, EmptyTransportResponseHandler.INSTANCE_SAME).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(OpenSearchException.class)); - assertThat(BaseExceptionsHelper.unwrapCause(e.getCause()).getMessage(), equalTo("simulated")); + assertThat(ExceptionsHelper.unwrapCause(e.getCause()).getMessage(), equalTo("simulated")); } // use assert busy as callbacks are called on a different thread @@ -577,7 +576,7 @@ public void onRequestSent( serviceB.submitRequest(nodeA, ACTION, TransportRequest.Empty.INSTANCE, EmptyTransportResponseHandler.INSTANCE_SAME).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(OpenSearchException.class)); - assertThat(BaseExceptionsHelper.unwrapCause(e.getCause()).getMessage(), equalTo("simulated")); + assertThat(ExceptionsHelper.unwrapCause(e.getCause()).getMessage(), equalTo("simulated")); } // use assert busy as callbacks are called on a different thread @@ -597,7 +596,7 @@ public void onRequestSent( serviceA.submitRequest(nodeA, ACTION, TransportRequest.Empty.INSTANCE, EmptyTransportResponseHandler.INSTANCE_SAME).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(OpenSearchException.class)); - assertThat(BaseExceptionsHelper.unwrapCause(e.getCause()).getMessage(), equalTo("simulated")); + assertThat(ExceptionsHelper.unwrapCause(e.getCause()).getMessage(), equalTo("simulated")); } // use assert busy as callbacks are called on a different thread @@ -1651,7 +1650,7 @@ public void handleResponse(StringMessageResponse response) { @Override public void handleException(TransportException exp) { - Throwable cause = BaseExceptionsHelper.unwrapCause(exp); + Throwable cause = ExceptionsHelper.unwrapCause(exp); assertThat(cause, instanceOf(ConnectTransportException.class)); assertThat(((ConnectTransportException) cause).node(), equalTo(nodeA)); } @@ -1662,7 +1661,7 @@ public void handleException(TransportException exp) { res.txGet(); fail("exception should be thrown"); } catch (Exception e) { - Throwable cause = BaseExceptionsHelper.unwrapCause(e); + Throwable cause = ExceptionsHelper.unwrapCause(e); assertThat(cause, instanceOf(ConnectTransportException.class)); assertThat(((ConnectTransportException) cause).node(), equalTo(nodeA)); } From ba1715e872cebe7f7ca784a9f59ea37e04cb2a80 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Fri, 16 Jun 2023 17:20:55 -0500 Subject: [PATCH 7/8] initial pr cleanup Signed-off-by: Nicholas Walter Knize --- .../common/bytes/AbstractBytesReference.java | 2 +- .../io/stream/InputStreamStreamInput.java | 2 +- .../common/io/stream/StreamInput.java | 2 +- .../common/io/stream/Writeable.java | 5 +-- .../org/opensearch/common/io/Streams.java | 32 ++----------------- .../io/stream/ByteBufferStreamInput.java | 2 +- .../common/io/stream/BytesStreamInput.java | 2 +- .../common/io/stream/FilterStreamInput.java | 2 +- .../org/opensearch/index/store/Store.java | 4 +-- 9 files changed, 12 insertions(+), 41 deletions(-) diff --git a/libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java b/libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java index 030c3ce03bec0..7b3c71321e4f0 100644 --- a/libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java +++ b/libs/core/src/main/java/org/opensearch/common/bytes/AbstractBytesReference.java @@ -313,7 +313,7 @@ public int available() { } @Override - public void ensureCanReadBytes(int bytesToRead) throws EOFException { + protected void ensureCanReadBytes(int bytesToRead) throws EOFException { int bytesAvailable = length() - offset(); if (bytesAvailable < bytesToRead) { throw new EOFException("tried to read: " + bytesToRead + " bytes but only " + bytesAvailable + " remaining"); diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java index 37c3081d19c75..a4bbdd1bfb1ac 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java @@ -132,7 +132,7 @@ public long skip(long n) throws IOException { } @Override - public void ensureCanReadBytes(int length) throws EOFException { + protected void ensureCanReadBytes(int length) throws EOFException { if (length > sizeLimit) { throw new EOFException("tried to read: " + length + " bytes but this stream is limited to: " + sizeLimit); } diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java index c528d70ca9a6d..c6915ae1f45b0 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/StreamInput.java @@ -1281,7 +1281,7 @@ private int readArraySize() throws IOException { * This method throws an {@link EOFException} if the given number of bytes can not be read from the this stream. This method might * be a no-op depending on the underlying implementation if the information of the remaining bytes is not present. */ - public abstract void ensureCanReadBytes(int length) throws EOFException; + protected abstract void ensureCanReadBytes(int length) throws EOFException; private static final TimeUnit[] TIME_UNITS = TimeUnit.values(); diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java b/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java index 8ebf16b5ecdb9..735413d3642ec 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/Writeable.java @@ -65,7 +65,6 @@ public static > void registerWriter(final Class clazz, fi if (WRITER_REGISTRY.putIfAbsent(clazz, writer) != null) { throw new IllegalArgumentException("Streamable writer already registered for type [" + clazz.getName() + "]"); } - WRITER_REGISTRY.put(clazz, writer); } /** @@ -77,14 +76,12 @@ public static > void registerReader(final byte ordinal, fina if (READER_REGISTRY.putIfAbsent(ordinal, reader) != null) { throw new IllegalArgumentException("Streamable reader already registered for ordinal [" + (int) ordinal + "]"); } - READER_REGISTRY.put(ordinal, reader); } public static void registerClassAlias(final Class classInstance, final Class classGeneric) { - if (WRITER_CUSTOM_CLASS_MAP.containsKey(classInstance)) { + if (WRITER_CUSTOM_CLASS_MAP.putIfAbsent(classInstance, classGeneric) != null) { throw new IllegalArgumentException("Streamable custom class already registered [" + classInstance.getClass() + "]"); } - WRITER_CUSTOM_CLASS_MAP.put(classInstance, classGeneric); } /** diff --git a/server/src/main/java/org/opensearch/common/io/Streams.java b/server/src/main/java/org/opensearch/common/io/Streams.java index 00e9c84e4c2aa..2a833b81cacca 100644 --- a/server/src/main/java/org/opensearch/common/io/Streams.java +++ b/server/src/main/java/org/opensearch/common/io/Streams.java @@ -36,6 +36,7 @@ import org.opensearch.common.io.stream.BytesStream; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.core.common.io.StreamsUtil; import java.io.BufferedReader; import java.io.FilterInputStream; @@ -162,36 +163,9 @@ public static String copyToString(Reader in) throws IOException { return out.toString(); } - public static int readFully(Reader reader, char[] dest) throws IOException { - return readFully(reader, dest, 0, dest.length); - } - - public static int readFully(Reader reader, char[] dest, int offset, int len) throws IOException { - int read = 0; - while (read < len) { - final int r = reader.read(dest, offset + read, len - read); - if (r == -1) { - break; - } - read += r; - } - return read; - } - + @Deprecated public static int readFully(InputStream reader, byte[] dest) throws IOException { - return readFully(reader, dest, 0, dest.length); - } - - public static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException { - int read = 0; - while (read < len) { - final int r = reader.read(dest, offset + read, len - read); - if (r == -1) { - break; - } - read += r; - } - return read; + return StreamsUtil.readFully(reader, dest, 0, dest.length); } /** diff --git a/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java index 22c83804f1518..707b32a0c50f3 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/ByteBufferStreamInput.java @@ -147,7 +147,7 @@ public int available() throws IOException { } @Override - public void ensureCanReadBytes(int length) throws EOFException { + protected void ensureCanReadBytes(int length) throws EOFException { if (buffer.remaining() < length) { throw new EOFException("tried to read: " + length + " bytes but only " + buffer.remaining() + " remaining"); } diff --git a/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java index fe87102f85cfc..8bf1fe846cd8b 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/BytesStreamInput.java @@ -106,7 +106,7 @@ public int available() { } @Override - public void ensureCanReadBytes(int length) throws EOFException { + protected void ensureCanReadBytes(int length) throws EOFException { int available = available(); if (length > available) { throw new EOFException("attempting to read " + length + " bytes but only " + available + " bytes are available"); diff --git a/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java index 82776eae51401..5f6bbd7c16cf3 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/FilterStreamInput.java @@ -106,7 +106,7 @@ public void setVersion(Version version) { } @Override - public void ensureCanReadBytes(int length) throws EOFException { + protected void ensureCanReadBytes(int length) throws EOFException { delegate.ensureCanReadBytes(length); } diff --git a/server/src/main/java/org/opensearch/index/store/Store.java b/server/src/main/java/org/opensearch/index/store/Store.java index 2c0d5decebba8..edb1473724e07 100644 --- a/server/src/main/java/org/opensearch/index/store/Store.java +++ b/server/src/main/java/org/opensearch/index/store/Store.java @@ -67,7 +67,6 @@ import org.opensearch.common.Nullable; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.io.Streams; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -83,6 +82,7 @@ import org.opensearch.common.util.concurrent.RefCounted; import org.opensearch.common.util.iterable.Iterables; import org.opensearch.common.util.io.IOUtils; +import org.opensearch.core.common.io.StreamsUtil; import org.opensearch.env.NodeEnvironment; import org.opensearch.env.ShardLock; import org.opensearch.env.ShardLockObtainFailedException; @@ -1240,7 +1240,7 @@ public static void hashFile(BytesRefBuilder fileHash, InputStream in, long size) final int len = (int) Math.min(1024 * 1024, size); // for safety we limit this to 1MB fileHash.grow(len); fileHash.setLength(len); - final int readBytes = Streams.readFully(in, fileHash.bytes(), 0, len); + final int readBytes = StreamsUtil.readFully(in, fileHash.bytes(), 0, len); assert readBytes == len : Integer.toString(readBytes) + " != " + Integer.toString(len); assert fileHash.length() == len : Integer.toString(fileHash.length()) + " != " + Integer.toString(len); } From 2843bb280b95972e61c0d05841f84ecd9c2a7a49 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Mon, 19 Jun 2023 11:21:33 -0500 Subject: [PATCH 8/8] more PR cleanup Signed-off-by: Nicholas Walter Knize --- .../java/org/opensearch/ExceptionsHelper.java | 2 +- .../DefaultShardOperationFailedException.java | 5 +-- .../opensearch/common/ParsingException.java | 3 +- .../io/stream/InputStreamStreamInput.java | 4 +-- .../core/common/io/StreamsUtil.java | 34 ------------------- .../org/opensearch/common/io/Streams.java | 3 +- .../org/opensearch/index/store/Store.java | 3 +- 7 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java diff --git a/libs/core/src/main/java/org/opensearch/ExceptionsHelper.java b/libs/core/src/main/java/org/opensearch/ExceptionsHelper.java index d5c905f5dc528..385dc24a0c25d 100644 --- a/libs/core/src/main/java/org/opensearch/ExceptionsHelper.java +++ b/libs/core/src/main/java/org/opensearch/ExceptionsHelper.java @@ -72,7 +72,7 @@ * @opensearch.internal */ public final class ExceptionsHelper { - protected static final Logger logger = LogManager.getLogger(ExceptionsHelper.class); + private static final Logger logger = LogManager.getLogger(ExceptionsHelper.class); // utility class: no ctor private ExceptionsHelper() {} diff --git a/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java index 71f0980e56d4b..5a7e48a5efef7 100644 --- a/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java +++ b/libs/core/src/main/java/org/opensearch/action/support/DefaultShardOperationFailedException.java @@ -47,6 +47,7 @@ import java.io.IOException; import static org.opensearch.ExceptionsHelper.detailedMessage; +import static org.opensearch.OpenSearchException.generateThrowableXContent; import static org.opensearch.core.xcontent.ConstructingObjectParser.constructorArg; /** @@ -93,7 +94,7 @@ public DefaultShardOperationFailedException(OpenSearchException e) { } public DefaultShardOperationFailedException(String index, int shardId, Throwable cause) { - super(index, shardId, ExceptionsHelper.detailedMessage(cause), ExceptionsHelper.status(cause), cause); + super(index, shardId, detailedMessage(cause), ExceptionsHelper.status(cause), cause); } public static DefaultShardOperationFailedException readShardOperationFailed(StreamInput in) throws IOException { @@ -135,7 +136,7 @@ protected XContentBuilder innerToXContent(XContentBuilder builder, Params params builder.field("status", status.name()); if (reason != null) { builder.startObject("reason"); - OpenSearchException.generateThrowableXContent(builder, params, cause); + generateThrowableXContent(builder, params, cause); builder.endObject(); } return builder; diff --git a/libs/core/src/main/java/org/opensearch/common/ParsingException.java b/libs/core/src/main/java/org/opensearch/common/ParsingException.java index 5991cc3d77eff..5a9e99f5987d9 100644 --- a/libs/core/src/main/java/org/opensearch/common/ParsingException.java +++ b/libs/core/src/main/java/org/opensearch/common/ParsingException.java @@ -35,7 +35,6 @@ import org.opensearch.OpenSearchException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentLocation; import org.opensearch.core.xcontent.XContentParser; @@ -112,7 +111,7 @@ public RestStatus status() { } @Override - protected void metadataToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { + protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException { if (lineNumber != UNKNOWN_POSITION) { builder.field("line", lineNumber); builder.field("col", columnNumber); diff --git a/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java b/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java index a4bbdd1bfb1ac..06e10c67cf972 100644 --- a/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java +++ b/libs/core/src/main/java/org/opensearch/common/io/stream/InputStreamStreamInput.java @@ -32,8 +32,6 @@ package org.opensearch.common.io.stream; -import org.opensearch.core.common.io.StreamsUtil; - import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -80,7 +78,7 @@ public byte readByte() throws IOException { @Override public void readBytes(byte[] b, int offset, int len) throws IOException { if (len < 0) throw new IndexOutOfBoundsException(); - final int read = StreamsUtil.readFully(is, b, offset, len); + final int read = is.readNBytes(b, offset, len); if (read != len) { throw new EOFException(); } diff --git a/libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java b/libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java deleted file mode 100644 index 6ef33a190c352..0000000000000 --- a/libs/core/src/main/java/org/opensearch/core/common/io/StreamsUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.core.common.io; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Util library for reading streams - * - * @opensearch.internal - */ -public final class StreamsUtil { - - private StreamsUtil() {} - - public static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException { - int read = 0; - while (read < len) { - final int r = reader.read(dest, offset + read, len - read); - if (r == -1) { - break; - } - read += r; - } - return read; - } -} diff --git a/server/src/main/java/org/opensearch/common/io/Streams.java b/server/src/main/java/org/opensearch/common/io/Streams.java index 2a833b81cacca..6e44f18b7f4d5 100644 --- a/server/src/main/java/org/opensearch/common/io/Streams.java +++ b/server/src/main/java/org/opensearch/common/io/Streams.java @@ -36,7 +36,6 @@ import org.opensearch.common.io.stream.BytesStream; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.core.common.io.StreamsUtil; import java.io.BufferedReader; import java.io.FilterInputStream; @@ -165,7 +164,7 @@ public static String copyToString(Reader in) throws IOException { @Deprecated public static int readFully(InputStream reader, byte[] dest) throws IOException { - return StreamsUtil.readFully(reader, dest, 0, dest.length); + return reader.readNBytes(dest, 0, dest.length); } /** diff --git a/server/src/main/java/org/opensearch/index/store/Store.java b/server/src/main/java/org/opensearch/index/store/Store.java index edb1473724e07..90832b4c77756 100644 --- a/server/src/main/java/org/opensearch/index/store/Store.java +++ b/server/src/main/java/org/opensearch/index/store/Store.java @@ -82,7 +82,6 @@ import org.opensearch.common.util.concurrent.RefCounted; import org.opensearch.common.util.iterable.Iterables; import org.opensearch.common.util.io.IOUtils; -import org.opensearch.core.common.io.StreamsUtil; import org.opensearch.env.NodeEnvironment; import org.opensearch.env.ShardLock; import org.opensearch.env.ShardLockObtainFailedException; @@ -1240,7 +1239,7 @@ public static void hashFile(BytesRefBuilder fileHash, InputStream in, long size) final int len = (int) Math.min(1024 * 1024, size); // for safety we limit this to 1MB fileHash.grow(len); fileHash.setLength(len); - final int readBytes = StreamsUtil.readFully(in, fileHash.bytes(), 0, len); + final int readBytes = in.readNBytes(fileHash.bytes(), 0, len); assert readBytes == len : Integer.toString(readBytes) + " != " + Integer.toString(len); assert fileHash.length() == len : Integer.toString(fileHash.length()) + " != " + Integer.toString(len); }