Skip to content

Commit

Permalink
[Refactor] OpenSearchException and ExceptionsHelper foundation to bas…
Browse files Browse the repository at this point in the history
…e class

Creates new BaseOpenSearchException and BaseExceptionsHelper in core
library as a step to moving OpenSearch exception mechanisms from the
server module to core library. This is a move to support serverless and
cloud native capabilities without requiring the server module for core
opensearch indexing, search, and compute capabilities.

Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize committed May 16, 2023
1 parent 6f65afb commit a754c94
Show file tree
Hide file tree
Showing 419 changed files with 1,817 additions and 1,484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.opensearch.client.indices.DeleteComponentTemplateRequest;
import org.opensearch.client.indices.GetComponentTemplatesRequest;
import org.opensearch.client.indices.PutComponentTemplateRequest;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import org.opensearch.client.indices.SimulateIndexTemplateRequest;
import org.opensearch.client.indices.rollover.RolloverRequest;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;

import java.io.IOException;
import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
import org.opensearch.cluster.health.ClusterHealthStatus;
import org.opensearch.common.Nullable;
import org.opensearch.common.Priority;
import org.opensearch.common.Strings;
import org.opensearch.common.SuppressForbidden;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.lucene.uid.Versions;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.CollectionUtils;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.ToXContent;
Expand Down Expand Up @@ -220,7 +220,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {

if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) {
IndexRequest indexRequest = (IndexRequest) action;
if (Strings.hasLength(indexRequest.getPipeline())) {
if (org.opensearch.core.common.Strings.hasLength(indexRequest.getPipeline())) {
metadata.field("pipeline", indexRequest.getPipeline());
}
} else if (opType == DocWriteRequest.OpType.UPDATE) {
Expand Down Expand Up @@ -338,7 +338,7 @@ static Request multiGet(MultiGetRequest multiGetRequest) throws IOException {
}

static Request index(IndexRequest indexRequest) {
String method = Strings.hasLength(indexRequest.id()) ? HttpPut.METHOD_NAME : HttpPost.METHOD_NAME;
String method = org.opensearch.core.common.Strings.hasLength(indexRequest.id()) ? HttpPut.METHOD_NAME : HttpPost.METHOD_NAME;

String endpoint;
if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) {
Expand Down Expand Up @@ -747,7 +747,7 @@ static Request putScript(PutStoredScriptRequest putStoredScriptRequest) throws I
Params params = new Params();
params.withTimeout(putStoredScriptRequest.timeout());
params.withClusterManagerTimeout(putStoredScriptRequest.clusterManagerNodeTimeout());
if (Strings.hasText(putStoredScriptRequest.context())) {
if (org.opensearch.core.common.Strings.hasText(putStoredScriptRequest.context())) {
params.putParam("context", putStoredScriptRequest.context());
}
request.addParameters(params.asMap());
Expand Down Expand Up @@ -903,7 +903,7 @@ static class Params {
Params() {}

Params putParam(String name, String value) {
if (Strings.hasLength(value)) {
if (org.opensearch.core.common.Strings.hasLength(value)) {
parameters.put(name, value);
}
return this;
Expand Down Expand Up @@ -1298,7 +1298,7 @@ static class EndpointBuilder {

EndpointBuilder addPathPart(String... parts) {
for (String part : parts) {
if (Strings.hasLength(part)) {
if (org.opensearch.core.common.Strings.hasLength(part)) {
joiner.add(encodePart(part));
}
}
Expand All @@ -1317,7 +1317,7 @@ EndpointBuilder addCommaSeparatedPathParts(List<String> parts) {

EndpointBuilder addPathPartAsIs(String... parts) {
for (String part : parts) {
if (Strings.hasLength(part)) {
if (org.opensearch.core.common.Strings.hasLength(part)) {
joiner.add(part);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.IndicesRequest;
import org.opensearch.action.support.IndicesOptions;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.query.QueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

package org.opensearch.client.indices;

import org.opensearch.core.common.Strings;
import org.opensearch.core.ParseField;
import org.opensearch.common.Strings;
import org.opensearch.core.xcontent.ConstructingObjectParser;
import org.opensearch.core.xcontent.XContentParser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import org.opensearch.action.support.IndicesOptions;
import org.opensearch.client.Validatable;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;

/** Request the mappings of specific fields */
public class GetFieldMappingsRequest implements Validatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.opensearch.client.TimedRequest;
import org.opensearch.client.Validatable;
import org.opensearch.common.Nullable;
import org.opensearch.common.Strings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.Strings;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import org.opensearch.action.support.IndicesOptions;
import org.opensearch.client.TimedRequest;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;

public class GetMappingsRequest extends TimedRequest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ org.apache.hc.core5.http.ContentType#create(java.lang.String,java.nio.charset.Ch
@defaultMessage ES's logging infrastructure uses log4j2 which we don't want to force on high level rest client users
org.opensearch.common.logging.DeprecationLogger
org.opensearch.common.logging.LogConfigurator
org.opensearch.common.logging.LoggerMessageFormat
org.opensearch.core.common.logging.LoggerMessageFormat
org.opensearch.common.logging.Loggers
org.opensearch.common.logging.NodeNamePatternConverter
org.opensearch.common.logging.PrefixLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
import org.opensearch.client.core.TermVectorsRequest;
import org.opensearch.client.core.TermVectorsResponse;
import org.opensearch.client.indices.GetIndexRequest;
import org.opensearch.common.Strings;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.cluster.metadata.Template;
import org.opensearch.common.Strings;
import org.opensearch.common.ValidationException;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.compress.CompressedXContent;
Expand All @@ -116,6 +115,7 @@
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
import org.opensearch.client.indices.ResizeRequest;
import org.opensearch.client.indices.rollover.RolloverRequest;
import org.opensearch.common.CheckedFunction;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.CollectionUtils;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.Strings;
import org.opensearch.test.OpenSearchTestCase;
import org.junit.Assert;
import org.opensearch.common.unit.ByteSizeValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@
import org.opensearch.client.core.TermVectorsRequest;
import org.opensearch.client.indices.AnalyzeRequest;
import org.opensearch.common.CheckedBiConsumer;
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.io.Streams;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.lucene.uid.Versions;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.VersionType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.MatchAllQueryBuilder;
Expand Down Expand Up @@ -1074,7 +1074,7 @@ public void testSearch() throws Exception {
Request request = RequestConverters.search(searchRequest, searchEndpoint);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
if (org.opensearch.core.common.Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add(searchEndpoint);
Expand Down Expand Up @@ -1179,7 +1179,7 @@ public void testCount() throws Exception {
Request request = RequestConverters.count(countRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
if (org.opensearch.core.common.Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add("_count");
Expand Down Expand Up @@ -1316,7 +1316,7 @@ public void testCreatePit() throws IOException {
Request request = RequestConverters.createPit(createPitRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
if (org.opensearch.core.common.Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add("_search/point_in_time");
Expand Down Expand Up @@ -1371,7 +1371,7 @@ public void testSearchTemplate() throws Exception {
Request request = RequestConverters.searchTemplate(searchTemplateRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
if (org.opensearch.core.common.Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add("_search/template");
Expand Down Expand Up @@ -1613,7 +1613,7 @@ public void testFieldCaps() throws IOException {
// a hash set before being added to the request, and can appear in a
// non-deterministic order.
assertThat(request.getParameters(), hasKey("fields"));
String[] requestFields = Strings.splitStringByCommaToArray(request.getParameters().get("fields"));
String[] requestFields = org.opensearch.core.common.Strings.splitStringByCommaToArray(request.getParameters().get("fields"));
assertEquals(new HashSet<>(Arrays.asList(fields)), new HashSet<>(Arrays.asList(requestFields)));

for (Map.Entry<String, String> param : indicesOptionsParams.entrySet()) {
Expand Down Expand Up @@ -1653,7 +1653,7 @@ public void testFieldCapsWithIndexFilter() throws IOException {
// a hash set before being added to the request, and can appear in a
// non-deterministic order.
assertThat(request.getParameters(), hasKey("fields"));
String[] requestFields = Strings.splitStringByCommaToArray(request.getParameters().get("fields"));
String[] requestFields = org.opensearch.core.common.Strings.splitStringByCommaToArray(request.getParameters().get("fields"));
assertEquals(new HashSet<>(Arrays.asList(fields)), new HashSet<>(Arrays.asList(requestFields)));

for (Map.Entry<String, String> param : indicesOptionsParams.entrySet()) {
Expand Down Expand Up @@ -1681,7 +1681,7 @@ public void testRankEval() throws Exception {
Request request = RequestConverters.rankEval(rankEvalRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
if (org.opensearch.core.common.Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add(RestRankEvalAction.ENDPOINT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.opensearch.action.support.IndicesOptions;
import org.opensearch.client.TimedRequest;
import org.opensearch.client.ValidationException;
import org.opensearch.common.Strings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.Strings;
import org.opensearch.test.OpenSearchTestCase;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

package org.opensearch.bootstrap;

import org.opensearch.common.Strings;
import org.opensearch.common.io.PathUtils;
import org.opensearch.core.common.Strings;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
Expand Down
Loading

0 comments on commit a754c94

Please sign in to comment.