[Rename] ElasticsearchStatusException in server module (#172)

This commit refactors the ElasticsearchStatusException in the server module to
OpenSearchStatusException. References and usages throughout the rest of the
codebase are fully refactored.

Signed-off-by: Nicholas Knize <nknize@amazon.com>
This commit is contained in:
Nick Knize 2021-03-03 17:03:42 -06:00
parent 1015c8e609
commit 64d7e7e9ca
19 changed files with 69 additions and 69 deletions

View File

@ -21,7 +21,7 @@ package org.elasticsearch.client;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
@ -1688,29 +1688,29 @@ public class RestHighLevelClient implements Closeable {
/** /**
* Converts a {@link ResponseException} obtained from the low level REST client into an {@link OpenSearchException}. * Converts a {@link ResponseException} obtained from the low level REST client into an {@link OpenSearchException}.
* If a response body was returned, tries to parse it as an error returned from Elasticsearch. * If a response body was returned, tries to parse it as an error returned from Elasticsearch.
* If no response body was returned or anything goes wrong while parsing the error, returns a new {@link ElasticsearchStatusException} * If no response body was returned or anything goes wrong while parsing the error, returns a new {@link OpenSearchStatusException}
* that wraps the original {@link ResponseException}. The potential exception obtained while parsing is added to the returned * that wraps the original {@link ResponseException}. The potential exception obtained while parsing is added to the returned
* exception as a suppressed exception. This method is guaranteed to not throw any exception eventually thrown while parsing. * exception as a suppressed exception. This method is guaranteed to not throw any exception eventually thrown while parsing.
*/ */
protected final ElasticsearchStatusException parseResponseException(ResponseException responseException) { protected final OpenSearchStatusException parseResponseException(ResponseException responseException) {
Response response = responseException.getResponse(); Response response = responseException.getResponse();
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
ElasticsearchStatusException elasticsearchException; OpenSearchStatusException opensearchException;
RestStatus restStatus = RestStatus.fromCode(response.getStatusLine().getStatusCode()); RestStatus restStatus = RestStatus.fromCode(response.getStatusLine().getStatusCode());
if (entity == null) { if (entity == null) {
elasticsearchException = new ElasticsearchStatusException( opensearchException = new OpenSearchStatusException(
responseException.getMessage(), restStatus, responseException); responseException.getMessage(), restStatus, responseException);
} else { } else {
try { try {
elasticsearchException = parseEntity(entity, BytesRestResponse::errorFromXContent); opensearchException = parseEntity(entity, BytesRestResponse::errorFromXContent);
elasticsearchException.addSuppressed(responseException); opensearchException.addSuppressed(responseException);
} catch (Exception e) { } catch (Exception e) {
elasticsearchException = new ElasticsearchStatusException("Unable to parse response body", restStatus, responseException); opensearchException = new OpenSearchStatusException("Unable to parse response body", restStatus, responseException);
elasticsearchException.addSuppressed(e); opensearchException.addSuppressed(e);
} }
} }
return elasticsearchException; return opensearchException;
} }
protected final <Resp> Resp parseEntity(final HttpEntity entity, protected final <Resp> Resp parseEntity(final HttpEntity entity,

View File

@ -21,7 +21,7 @@ package org.elasticsearch.client;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest;
@ -387,7 +387,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
highLevelClient().cluster()::deleteComponentTemplateAsync); highLevelClient().cluster()::deleteComponentTemplateAsync);
assertThat(response.isAcknowledged(), equalTo(true)); assertThat(response.isAcknowledged(), equalTo(true));
ElasticsearchStatusException statusException = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException statusException = expectThrows(OpenSearchStatusException.class,
() -> execute(getComponentTemplatesRequest, () -> execute(getComponentTemplatesRequest,
highLevelClient().cluster()::getComponentTemplate, highLevelClient().cluster()::getComponentTemplateAsync)); highLevelClient().cluster()::getComponentTemplate, highLevelClient().cluster()::getComponentTemplateAsync));

View File

@ -20,7 +20,7 @@
package org.elasticsearch.client; package org.elasticsearch.client;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.bulk.BulkItemResponse;
@ -146,7 +146,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
highLevelClient().index( highLevelClient().index(
new IndexRequest("index").id(docId).source(Collections.singletonMap("foo", "bar")) new IndexRequest("index").id(docId).source(Collections.singletonMap("foo", "bar"))
.versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT); .versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT);
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () -> {
DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(10); DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(10);
execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
}); });
@ -594,7 +594,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals("id", indexResponse.getId()); assertEquals("id", indexResponse.getId());
assertEquals(2L, indexResponse.getVersion()); assertEquals(2L, indexResponse.getVersion());
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () -> {
IndexRequest wrongRequest = new IndexRequest("index").id("id"); IndexRequest wrongRequest = new IndexRequest("index").id("id");
wrongRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject()); wrongRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject());
wrongRequest.setIfSeqNo(1L).setIfPrimaryTerm(5L); wrongRequest.setIfSeqNo(1L).setIfPrimaryTerm(5L);
@ -608,7 +608,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals("index", exception.getMetadata("es.index").get(0)); assertEquals("index", exception.getMetadata("es.index").get(0));
} }
{ {
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () -> {
IndexRequest indexRequest = new IndexRequest("index").id("missing_pipeline"); IndexRequest indexRequest = new IndexRequest("index").id("missing_pipeline");
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject()); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject());
indexRequest.setPipeline("missing"); indexRequest.setPipeline("missing");
@ -644,7 +644,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals("_doc", indexResponse.getType()); assertEquals("_doc", indexResponse.getType());
assertEquals("with_create_op_type", indexResponse.getId()); assertEquals("with_create_op_type", indexResponse.getId());
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () -> {
execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
}); });
@ -675,7 +675,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
UpdateRequest updateRequest = new UpdateRequest("index", "does_not_exist"); UpdateRequest updateRequest = new UpdateRequest("index", "does_not_exist");
updateRequest.doc(singletonMap("field", "value"), randomFrom(XContentType.values())); updateRequest.doc(singletonMap("field", "value"), randomFrom(XContentType.values()));
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () ->
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync)); execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status()); assertEquals(RestStatus.NOT_FOUND, exception.status());
assertEquals("Elasticsearch exception [type=document_missing_exception, reason=[_doc][does_not_exist]: document missing]", assertEquals("Elasticsearch exception [type=document_missing_exception, reason=[_doc][does_not_exist]: document missing]",
@ -712,7 +712,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
updateRequest.setIfSeqNo(lastUpdateSeqNo + (randomBoolean() ? 0 : 1)); updateRequest.setIfSeqNo(lastUpdateSeqNo + (randomBoolean() ? 0 : 1));
updateRequest.setIfPrimaryTerm(lastUpdatePrimaryTerm + 1); updateRequest.setIfPrimaryTerm(lastUpdatePrimaryTerm + 1);
} }
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () ->
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync)); execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync));
assertEquals(exception.toString(),RestStatus.CONFLICT, exception.status()); assertEquals(exception.toString(),RestStatus.CONFLICT, exception.status());
assertThat(exception.getMessage(), containsString("Elasticsearch exception [type=version_conflict_engine_exception")); assertThat(exception.getMessage(), containsString("Elasticsearch exception [type=version_conflict_engine_exception"));

View File

@ -23,7 +23,7 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
@ -826,7 +826,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
IndicesAliasesRequest mixedRequest = new IndicesAliasesRequest(); IndicesAliasesRequest mixedRequest = new IndicesAliasesRequest();
mixedRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).indices(index).aliases(alias)); mixedRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).indices(index).aliases(alias));
mixedRequest.addAliasAction(new AliasActions(AliasActions.Type.REMOVE).indices(nonExistentIndex).alias(alias)); mixedRequest.addAliasAction(new AliasActions(AliasActions.Type.REMOVE).indices(nonExistentIndex).alias(alias));
exception = expectThrows(ElasticsearchStatusException.class, exception = expectThrows(OpenSearchStatusException.class,
() -> execute(mixedRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync)); () -> execute(mixedRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync));
assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
assertThat(exception.getMessage(), assertThat(exception.getMessage(),
@ -1651,7 +1651,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
.alias(new Alias("alias-1").indexRouting("abc")).alias(new Alias("{index}-write").searchRouting("xyz")); .alias(new Alias("alias-1").indexRouting("abc")).alias(new Alias("{index}-write").searchRouting("xyz"));
ElasticsearchStatusException badMappingError = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException badMappingError = expectThrows(OpenSearchStatusException.class,
() -> execute(putTemplateRequest, () -> execute(putTemplateRequest,
highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync)); highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync));
assertThat(badMappingError.getDetailedMessage(), assertThat(badMappingError.getDetailedMessage(),
@ -1719,7 +1719,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
PutIndexTemplateRequest unknownSettingTemplate = new PutIndexTemplateRequest("t3") PutIndexTemplateRequest unknownSettingTemplate = new PutIndexTemplateRequest("t3")
.patterns(Collections.singletonList("any")) .patterns(Collections.singletonList("any"))
.settings(Settings.builder().put("this-setting-does-not-exist", 100)); .settings(Settings.builder().put("this-setting-does-not-exist", 100));
ElasticsearchStatusException unknownSettingError = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException unknownSettingError = expectThrows(OpenSearchStatusException.class,
() -> execute(unknownSettingTemplate, client.indices()::putTemplate, client.indices()::putTemplateAsync)); () -> execute(unknownSettingTemplate, client.indices()::putTemplate, client.indices()::putTemplateAsync));
assertThat(unknownSettingError.getDetailedMessage(), containsString("unknown setting [index.this-setting-does-not-exist]")); assertThat(unknownSettingError.getDetailedMessage(), containsString("unknown setting [index.this-setting-does-not-exist]"));
} }
@ -2077,7 +2077,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
getDataStreamRequest = new GetDataStreamRequest(dataStreamName); getDataStreamRequest = new GetDataStreamRequest(dataStreamName);
GetDataStreamRequest finalGetDataStreamRequest = getDataStreamRequest; GetDataStreamRequest finalGetDataStreamRequest = getDataStreamRequest;
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> execute(finalGetDataStreamRequest, OpenSearchStatusException e = expectThrows(OpenSearchStatusException.class, () -> execute(finalGetDataStreamRequest,
indices::getDataStream, indices::getDataStreamAsync)); indices::getDataStream, indices::getDataStreamAsync));
assertThat(e.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(e.status(), equalTo(RestStatus.NOT_FOUND));
} }
@ -2117,7 +2117,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
highLevelClient().indices()::deleteIndexTemplateAsync); highLevelClient().indices()::deleteIndexTemplateAsync);
assertThat(response.isAcknowledged(), equalTo(true)); assertThat(response.isAcknowledged(), equalTo(true));
ElasticsearchStatusException statusException = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException statusException = expectThrows(OpenSearchStatusException.class,
() -> execute(getComposableIndexTemplateRequest, () -> execute(getComposableIndexTemplateRequest,
highLevelClient().indices()::getIndexTemplate, highLevelClient().indices()::getIndexTemplateAsync)); highLevelClient().indices()::getIndexTemplate, highLevelClient().indices()::getIndexTemplateAsync));

View File

@ -22,7 +22,7 @@ package org.elasticsearch.client;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.explain.ExplainRequest; import org.elasticsearch.action.explain.ExplainRequest;
import org.elasticsearch.action.explain.ExplainResponse; import org.elasticsearch.action.explain.ExplainResponse;
import org.elasticsearch.action.fieldcaps.FieldCapabilities; import org.elasticsearch.action.fieldcaps.FieldCapabilities;
@ -340,7 +340,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
searchSourceBuilder.size(0); searchSourceBuilder.size(0);
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class,
() -> execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync)); () -> execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync));
assertEquals(RestStatus.BAD_REQUEST, exception.status()); assertEquals(RestStatus.BAD_REQUEST, exception.status());
} }
@ -722,7 +722,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
assertTrue(clearScrollResponse.isSucceeded()); assertTrue(clearScrollResponse.isSucceeded());
SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)); SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2));
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> execute(scrollRequest, OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () -> execute(scrollRequest,
highLevelClient()::scroll, highLevelClient()::scrollAsync)); highLevelClient()::scroll, highLevelClient()::scrollAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status()); assertEquals(RestStatus.NOT_FOUND, exception.status());
assertThat(exception.getRootCause(), instanceOf(OpenSearchException.class)); assertThat(exception.getRootCause(), instanceOf(OpenSearchException.class));
@ -954,7 +954,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
searchTemplateRequest.setScript("non-existent"); searchTemplateRequest.setScript("non-existent");
searchTemplateRequest.setScriptParams(Collections.emptyMap()); searchTemplateRequest.setScriptParams(Collections.emptyMap());
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class,
() -> execute(searchTemplateRequest, () -> execute(searchTemplateRequest,
highLevelClient()::searchTemplate, highLevelClient()::searchTemplate,
highLevelClient()::searchTemplateAsync)); highLevelClient()::searchTemplateAsync));
@ -1073,7 +1073,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
multiSearchTemplateRequest.add(badRequest2); multiSearchTemplateRequest.add(badRequest2);
// The whole HTTP request should fail if no nested search requests are valid // The whole HTTP request should fail if no nested search requests are valid
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class,
() -> execute(multiSearchTemplateRequest, highLevelClient()::msearchTemplate, () -> execute(multiSearchTemplateRequest, highLevelClient()::msearchTemplate,
highLevelClient()::msearchTemplateAsync)); highLevelClient()::msearchTemplateAsync));

View File

@ -18,7 +18,7 @@ package org.elasticsearch.client;
* under the License. * under the License.
*/ */
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse; import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
@ -76,7 +76,7 @@ public class StoredScriptsIT extends ESRestHighLevelClientTestCase {
GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id); GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id);
final ElasticsearchStatusException statusException = expectThrows(ElasticsearchStatusException.class, final OpenSearchStatusException statusException = expectThrows(OpenSearchStatusException.class,
() -> execute(getRequest, highLevelClient()::getScript, () -> execute(getRequest, highLevelClient()::getScript,
highLevelClient()::getScriptAsync)); highLevelClient()::getScriptAsync));
assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND));

View File

@ -18,7 +18,7 @@
*/ */
package org.elasticsearch.client.indices; package org.elasticsearch.client.indices;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse; import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse;
import org.elasticsearch.client.AbstractResponseTestCase; import org.elasticsearch.client.AbstractResponseTestCase;
@ -215,7 +215,7 @@ public class CloseIndexResponseTests extends
Exception exception = randomFrom(new IndexNotFoundException(indexName), Exception exception = randomFrom(new IndexNotFoundException(indexName),
new ActionNotFoundTransportException("test"), new ActionNotFoundTransportException("test"),
new IOException("boom", new NullPointerException()), new IOException("boom", new NullPointerException()),
new ElasticsearchStatusException("something", RestStatus.TOO_MANY_REQUESTS)); new OpenSearchStatusException("something", RestStatus.TOO_MANY_REQUESTS));
return new org.elasticsearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure(indexName, shard, exception, nodeId); return new org.elasticsearch.action.admin.indices.close.CloseIndexResponse.ShardResult.Failure(indexName, shard, exception, nodeId);
} }
} }

View File

@ -26,8 +26,8 @@ import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier; import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.bulk.BackoffPolicy; import org.elasticsearch.action.bulk.BackoffPolicy;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
@ -230,7 +230,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
* not have a constant for the status code so in that case we just use 500 instead. We also extract make sure to include the response * not have a constant for the status code so in that case we just use 500 instead. We also extract make sure to include the response
* body in the message so the user can figure out *why* the remote Elasticsearch service threw the error back to us. * body in the message so the user can figure out *why* the remote Elasticsearch service threw the error back to us.
*/ */
static ElasticsearchStatusException wrapExceptionToPreserveStatus(int statusCode, @Nullable HttpEntity entity, Exception cause) { static OpenSearchStatusException wrapExceptionToPreserveStatus(int statusCode, @Nullable HttpEntity entity, Exception cause) {
RestStatus status = RestStatus.fromCode(statusCode); RestStatus status = RestStatus.fromCode(statusCode);
String messagePrefix = ""; String messagePrefix = "";
if (status == null) { if (status == null) {
@ -238,9 +238,9 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
status = RestStatus.INTERNAL_SERVER_ERROR; status = RestStatus.INTERNAL_SERVER_ERROR;
} }
try { try {
return new ElasticsearchStatusException(messagePrefix + bodyMessage(entity), status, cause); return new OpenSearchStatusException(messagePrefix + bodyMessage(entity), status, cause);
} catch (IOException ioe) { } catch (IOException ioe) {
ElasticsearchStatusException e = new ElasticsearchStatusException(messagePrefix + "Failed to extract body.", status, cause); OpenSearchStatusException e = new OpenSearchStatusException(messagePrefix + "Failed to extract body.", status, cause);
e.addSuppressed(ioe); e.addSuppressed(ioe);
return e; return e;
} }

View File

@ -21,7 +21,7 @@ package org.elasticsearch.index.reindex;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
import org.elasticsearch.OpenSearchSecurityException; import org.elasticsearch.OpenSearchSecurityException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
@ -123,7 +123,7 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase {
public void testReindexSendsHeaders() throws Exception { public void testReindexSendsHeaders() throws Exception {
ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest")
.setRemoteInfo(newRemoteInfo(null, null, singletonMap(TestFilter.EXAMPLE_HEADER, "doesn't matter"))); .setRemoteInfo(newRemoteInfo(null, null, singletonMap(TestFilter.EXAMPLE_HEADER, "doesn't matter")));
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get()); OpenSearchStatusException e = expectThrows(OpenSearchStatusException.class, () -> request.get());
assertEquals(RestStatus.BAD_REQUEST, e.status()); assertEquals(RestStatus.BAD_REQUEST, e.status());
assertThat(e.getMessage(), containsString("Hurray! Sent the header!")); assertThat(e.getMessage(), containsString("Hurray! Sent the header!"));
} }
@ -131,7 +131,7 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase {
public void testReindexWithoutAuthenticationWhenRequired() throws Exception { public void testReindexWithoutAuthenticationWhenRequired() throws Exception {
ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest")
.setRemoteInfo(newRemoteInfo(null, null, emptyMap())); .setRemoteInfo(newRemoteInfo(null, null, emptyMap()));
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get()); OpenSearchStatusException e = expectThrows(OpenSearchStatusException.class, () -> request.get());
assertEquals(RestStatus.UNAUTHORIZED, e.status()); assertEquals(RestStatus.UNAUTHORIZED, e.status());
assertThat(e.getMessage(), containsString("\"reason\":\"Authentication required\"")); assertThat(e.getMessage(), containsString("\"reason\":\"Authentication required\""));
assertThat(e.getMessage(), containsString("\"WWW-Authenticate\":\"Basic realm=auth-realm\"")); assertThat(e.getMessage(), containsString("\"WWW-Authenticate\":\"Basic realm=auth-realm\""));
@ -140,7 +140,7 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase {
public void testReindexWithBadAuthentication() throws Exception { public void testReindexWithBadAuthentication() throws Exception {
ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest")
.setRemoteInfo(newRemoteInfo("junk", "auth", emptyMap())); .setRemoteInfo(newRemoteInfo("junk", "auth", emptyMap()));
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get()); OpenSearchStatusException e = expectThrows(OpenSearchStatusException.class, () -> request.get());
assertThat(e.getMessage(), containsString("\"reason\":\"Bad Authorization\"")); assertThat(e.getMessage(), containsString("\"reason\":\"Bad Authorization\""));
} }

View File

@ -37,7 +37,7 @@ import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine; import org.apache.http.message.BasicStatusLine;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.bulk.BackoffPolicy; import org.elasticsearch.action.bulk.BackoffPolicy;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
@ -381,7 +381,7 @@ public class RemoteScrollableHitSourceTests extends ESTestCase {
// Successfully get the status without a body // Successfully get the status without a body
RestStatus status = randomFrom(RestStatus.values()); RestStatus status = randomFrom(RestStatus.values());
ElasticsearchStatusException wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(status.getStatus(), null, cause); OpenSearchStatusException wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(status.getStatus(), null, cause);
assertEquals(status, wrapped.status()); assertEquals(status, wrapped.status());
assertEquals(cause, wrapped.getCause()); assertEquals(cause, wrapped.getCause());
assertEquals("No error body.", wrapped.getMessage()); assertEquals("No error body.", wrapped.getMessage());

View File

@ -19,7 +19,7 @@
package org.elasticsearch.upgrades; package org.elasticsearch.upgrades;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus; import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus;
@ -221,7 +221,7 @@ public class MultiVersionRepositoryAccessIT extends ESRestTestCase {
if (SnapshotsService.useIndexGenerations(minimumNodeVersion()) == false) { if (SnapshotsService.useIndexGenerations(minimumNodeVersion()) == false) {
assertThat(TEST_STEP, is(TestStep.STEP3_OLD_CLUSTER)); assertThat(TEST_STEP, is(TestStep.STEP3_OLD_CLUSTER));
final List<Class<? extends Exception>> expectedExceptions = final List<Class<? extends Exception>> expectedExceptions =
Arrays.asList(ResponseException.class, ElasticsearchStatusException.class); Arrays.asList(ResponseException.class, OpenSearchStatusException.class);
expectThrowsAnyOf(expectedExceptions, () -> listSnapshots(repoName)); expectThrowsAnyOf(expectedExceptions, () -> listSnapshots(repoName));
expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-1")); expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-1"));
expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-2")); expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-2"));

View File

@ -993,7 +993,7 @@ public class OpenSearchException extends RuntimeException implements ToXContentF
UNKNOWN_VERSION_ADDED), UNKNOWN_VERSION_ADDED),
NOT_MASTER_EXCEPTION(org.elasticsearch.cluster.NotMasterException.class, org.elasticsearch.cluster.NotMasterException::new, 144, NOT_MASTER_EXCEPTION(org.elasticsearch.cluster.NotMasterException.class, org.elasticsearch.cluster.NotMasterException::new, 144,
UNKNOWN_VERSION_ADDED), UNKNOWN_VERSION_ADDED),
STATUS_EXCEPTION(org.elasticsearch.ElasticsearchStatusException.class, org.elasticsearch.ElasticsearchStatusException::new, 145, STATUS_EXCEPTION(org.elasticsearch.OpenSearchStatusException.class, org.elasticsearch.OpenSearchStatusException::new, 145,
UNKNOWN_VERSION_ADDED), UNKNOWN_VERSION_ADDED),
TASK_CANCELLED_EXCEPTION(org.elasticsearch.tasks.TaskCancelledException.class, TASK_CANCELLED_EXCEPTION(org.elasticsearch.tasks.TaskCancelledException.class,
org.elasticsearch.tasks.TaskCancelledException::new, 146, UNKNOWN_VERSION_ADDED), org.elasticsearch.tasks.TaskCancelledException::new, 146, UNKNOWN_VERSION_ADDED),

View File

@ -26,7 +26,7 @@ import java.io.IOException;
/** /**
* Generic security exception * Generic security exception
*/ */
public class OpenSearchSecurityException extends ElasticsearchStatusException { public class OpenSearchSecurityException extends OpenSearchStatusException {
/** /**
* Build the exception with a specific status and cause. * Build the exception with a specific status and cause.
*/ */

View File

@ -29,13 +29,13 @@ import java.io.IOException;
* Exception who's {@link RestStatus} is arbitrary rather than derived. Used, for example, by reindex-from-remote to wrap remote exceptions * Exception who's {@link RestStatus} is arbitrary rather than derived. Used, for example, by reindex-from-remote to wrap remote exceptions
* that contain a status. * that contain a status.
*/ */
public class ElasticsearchStatusException extends OpenSearchException { public class OpenSearchStatusException extends OpenSearchException {
private final RestStatus status; private final RestStatus status;
/** /**
* Build the exception with a specific status and cause. * Build the exception with a specific status and cause.
*/ */
public ElasticsearchStatusException(String msg, RestStatus status, Throwable cause, Object... args) { public OpenSearchStatusException(String msg, RestStatus status, Throwable cause, Object... args) {
super(msg, cause, args); super(msg, cause, args);
this.status = status; this.status = status;
} }
@ -43,14 +43,14 @@ public class ElasticsearchStatusException extends OpenSearchException {
/** /**
* Build the exception without a cause. * Build the exception without a cause.
*/ */
public ElasticsearchStatusException(String msg, RestStatus status, Object... args) { public OpenSearchStatusException(String msg, RestStatus status, Object... args) {
this(msg, status, null, args); this(msg, status, null, args);
} }
/** /**
* Read from a stream. * Read from a stream.
*/ */
public ElasticsearchStatusException(StreamInput in) throws IOException { public OpenSearchStatusException(StreamInput in) throws IOException {
super(in); super(in);
status = RestStatus.readFrom(in); status = RestStatus.readFrom(in);
} }

View File

@ -20,7 +20,7 @@ package org.elasticsearch.cluster.metadata;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.ResourceAlreadyExistsException; import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
@ -152,10 +152,10 @@ public class MetadataCreateDataStreamService {
try { try {
currentState = metadataCreateIndexService.applyCreateIndexRequest(currentState, createIndexRequest, false); currentState = metadataCreateIndexService.applyCreateIndexRequest(currentState, createIndexRequest, false);
} catch (ResourceAlreadyExistsException e) { } catch (ResourceAlreadyExistsException e) {
// Rethrow as ElasticsearchStatusException, so that bulk transport action doesn't ignore it during // Rethrow as OpenSearchStatusException, so that bulk transport action doesn't ignore it during
// auto index/data stream creation. // auto index/data stream creation.
// (otherwise bulk execution fails later, because data stream will also not have been created) // (otherwise bulk execution fails later, because data stream will also not have been created)
throw new ElasticsearchStatusException("data stream could not be created because backing index [{}] already exists", throw new OpenSearchStatusException("data stream could not be created because backing index [{}] already exists",
RestStatus.BAD_REQUEST, e, firstBackingIndexName); RestStatus.BAD_REQUEST, e, firstBackingIndexName);
} }
IndexMetadata firstBackingIndex = currentState.metadata().index(firstBackingIndexName); IndexMetadata firstBackingIndex = currentState.metadata().index(firstBackingIndexName);

View File

@ -24,7 +24,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier; import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
@ -158,7 +158,7 @@ public class BytesRestResponse extends RestResponse {
.endObject()); .endObject());
} }
public static ElasticsearchStatusException errorFromXContent(XContentParser parser) throws IOException { public static OpenSearchStatusException errorFromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser);
@ -184,7 +184,7 @@ public class BytesRestResponse extends RestResponse {
throw new IllegalStateException("Failed to parse elasticsearch status exception: no exception was found"); throw new IllegalStateException("Failed to parse elasticsearch status exception: no exception was found");
} }
ElasticsearchStatusException result = new ElasticsearchStatusException(exception.getMessage(), status, exception.getCause()); OpenSearchStatusException result = new OpenSearchStatusException(exception.getMessage(), status, exception.getCause());
for (String header : exception.getHeaderKeys()) { for (String header : exception.getHeaderKeys()) {
result.addHeader(header, exception.getHeader(header)); result.addHeader(header, exception.getHeader(header));
} }

View File

@ -816,7 +816,7 @@ public class ExceptionSerializationTests extends ESTestCase {
ids.put(142, ShardStateAction.NoLongerPrimaryShardException.class); ids.put(142, ShardStateAction.NoLongerPrimaryShardException.class);
ids.put(143, org.elasticsearch.script.ScriptException.class); ids.put(143, org.elasticsearch.script.ScriptException.class);
ids.put(144, org.elasticsearch.cluster.NotMasterException.class); ids.put(144, org.elasticsearch.cluster.NotMasterException.class);
ids.put(145, org.elasticsearch.ElasticsearchStatusException.class); ids.put(145, OpenSearchStatusException.class);
ids.put(146, org.elasticsearch.tasks.TaskCancelledException.class); ids.put(146, org.elasticsearch.tasks.TaskCancelledException.class);
ids.put(147, org.elasticsearch.env.ShardLockObtainFailedException.class); ids.put(147, org.elasticsearch.env.ShardLockObtainFailedException.class);
ids.put(148, null); ids.put(148, null);
@ -885,8 +885,8 @@ public class ExceptionSerializationTests extends ESTestCase {
} }
public void testElasticsearchRemoteException() throws IOException { public void testElasticsearchRemoteException() throws IOException {
ElasticsearchStatusException ex = new ElasticsearchStatusException("something", RestStatus.TOO_MANY_REQUESTS); OpenSearchStatusException ex = new OpenSearchStatusException("something", RestStatus.TOO_MANY_REQUESTS);
ElasticsearchStatusException e = serialize(ex); OpenSearchStatusException e = serialize(ex);
assertEquals(ex.status(), e.status()); assertEquals(ex.status(), e.status());
assertEquals(RestStatus.TOO_MANY_REQUESTS, e.status()); assertEquals(RestStatus.TOO_MANY_REQUESTS, e.status());
} }

View File

@ -20,7 +20,7 @@
package org.elasticsearch.action.bulk; package org.elasticsearch.action.bulk;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.DocWriteRequest;
@ -191,7 +191,7 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
// Preemptively abort one of the bulk items, but allow the others to proceed // Preemptively abort one of the bulk items, but allow the others to proceed
BulkItemRequest rejectItem = randomFrom(items); BulkItemRequest rejectItem = randomFrom(items);
RestStatus rejectionStatus = randomFrom(RestStatus.BAD_REQUEST, RestStatus.CONFLICT, RestStatus.FORBIDDEN, RestStatus.LOCKED); RestStatus rejectionStatus = randomFrom(RestStatus.BAD_REQUEST, RestStatus.CONFLICT, RestStatus.FORBIDDEN, RestStatus.LOCKED);
final ElasticsearchStatusException rejectionCause = new ElasticsearchStatusException("testing rejection", rejectionStatus); final OpenSearchStatusException rejectionCause = new OpenSearchStatusException("testing rejection", rejectionStatus);
rejectItem.abort("index", rejectionCause); rejectItem.abort("index", rejectionCause);
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);

View File

@ -19,8 +19,8 @@
package org.elasticsearch.rest; package org.elasticsearch.rest;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.OpenSearchStatusException;
import org.elasticsearch.OpenSearchException; import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ResourceAlreadyExistsException; import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.ResourceNotFoundException;
@ -259,13 +259,13 @@ public class BytesRestResponseTests extends ESTestCase {
break; break;
case 5: case 5:
status = randomFrom(RestStatus.values()); status = randomFrom(RestStatus.values());
original = new ElasticsearchStatusException("ElasticsearchStatusException with random status", status); original = new OpenSearchStatusException("OpenSearchStatusException with random status", status);
if (detailed) { if (detailed) {
addHeadersOrMetadata = randomBoolean(); addHeadersOrMetadata = randomBoolean();
type = "status_exception"; type = "status_exception";
reason = "ElasticsearchStatusException with random status"; reason = "OpenSearchStatusException with random status";
} else { } else {
reason = "ElasticsearchStatusException[ElasticsearchStatusException with random status]"; reason = "OpenSearchStatusException[OpenSearchStatusException with random status]";
} }
break; break;
default: default:
@ -273,7 +273,7 @@ public class BytesRestResponseTests extends ESTestCase {
} }
String message = "Elasticsearch exception [type=" + type + ", reason=" + reason + "]"; String message = "Elasticsearch exception [type=" + type + ", reason=" + reason + "]";
ElasticsearchStatusException expected = new ElasticsearchStatusException(message, status, cause); OpenSearchStatusException expected = new OpenSearchStatusException(message, status, cause);
if (addHeadersOrMetadata) { if (addHeadersOrMetadata) {
OpenSearchException originalException = ((OpenSearchException) original); OpenSearchException originalException = ((OpenSearchException) original);