Skip to content

Commit

Permalink
[Rename] ElasticsearchException class in server module (#165)
Browse files Browse the repository at this point in the history
This commit refactors the ElasticsearchException class located in the server module
to OpenSearchException. References and usages throughout the rest of the
codebase are fully refactored.

Signed-off-by: Nicholas Knize <[email protected]>
  • Loading branch information
nknize committed Mar 22, 2021
1 parent 5427b38 commit ccceb38
Show file tree
Hide file tree
Showing 419 changed files with 1,552 additions and 1,552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.client.benchmark.BenchmarkTask;
import org.elasticsearch.client.benchmark.metrics.Sample;
import org.elasticsearch.client.benchmark.metrics.SampleRecorder;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void execute() {
sendBulk(bulkData);
}
} catch (IOException e) {
throw new ElasticsearchException(e);
throw new OpenSearchException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
Expand Down Expand Up @@ -84,7 +84,7 @@ public boolean bulkIndex(List<String> bulkData) {
Response response = client.performRequest(request);
return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
} catch (Exception e) {
throw new ElasticsearchException(e);
throw new OpenSearchException(e);
}
}
}
Expand All @@ -106,7 +106,7 @@ public boolean search(String source) {
Response response = client.performRequest(request);
return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
} catch (IOException e) {
throw new ElasticsearchException(e);
throw new OpenSearchException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.elasticsearch.client.benchmark.transport;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
Expand Down Expand Up @@ -91,7 +91,7 @@ public boolean bulkIndex(List<String> bulkData) {
Thread.currentThread().interrupt();
return false;
} catch (ExecutionException e) {
throw new ElasticsearchException(e);
throw new OpenSearchException(e);
}
return !bulkResponse.hasFailures();
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public boolean search(String source) {
Thread.currentThread().interrupt();
return false;
} catch (ExecutionException e) {
throw new ElasticsearchException(e);
throw new OpenSearchException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.client;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.common.xcontent.StatusToXContentObject;
import org.elasticsearch.common.xcontent.ToXContent;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class GetAliasesResponse implements StatusToXContentObject {

private final RestStatus status;
private final String error;
private final ElasticsearchException exception;
private final OpenSearchException exception;

private final Map<String, Set<AliasMetadata>> aliases;

Expand All @@ -61,7 +61,7 @@ public class GetAliasesResponse implements StatusToXContentObject {
this.exception = null;
}

private GetAliasesResponse(RestStatus status, ElasticsearchException exception) {
private GetAliasesResponse(RestStatus status, OpenSearchException exception) {
this.status = status;
this.error = null;
this.aliases = Collections.emptyMap();
Expand All @@ -83,7 +83,7 @@ public String getError() {
/**
* Return the exception that may have been returned
*/
public ElasticsearchException getException() {
public OpenSearchException getException() {
return exception;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public static GetAliasesResponse fromXContent(XContentParser parser) throws IOEx
String currentFieldName;
Token token;
String error = null;
ElasticsearchException exception = null;
OpenSearchException exception = null;
RestStatus status = RestStatus.OK;

while (parser.nextToken() != Token.END_OBJECT) {
Expand All @@ -152,7 +152,7 @@ public static GetAliasesResponse fromXContent(XContentParser parser) throws IOEx
error = parser.text();
} else if (token == Token.START_OBJECT) {
parser.nextToken();
exception = ElasticsearchException.innerFromXContent(parser, true);
exception = OpenSearchException.innerFromXContent(parser, true);
} else if (token == Token.START_ARRAY) {
parser.skipChildren();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.elasticsearch.client;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
Expand Down Expand Up @@ -52,7 +52,7 @@ public final class NodesResponseHeader {
int total = (Integer) a[i++];
int successful = (Integer) a[i++];
int failed = (Integer) a[i++];
List<ElasticsearchException> failures = (List<ElasticsearchException>) a[i++];
List<OpenSearchException> failures = (List<OpenSearchException>) a[i++];
return new NodesResponseHeader(total, successful, failed, failures);
});

Expand All @@ -61,15 +61,15 @@ public final class NodesResponseHeader {
PARSER.declareInt(ConstructingObjectParser.constructorArg(), SUCCESSFUL);
PARSER.declareInt(ConstructingObjectParser.constructorArg(), FAILED);
PARSER.declareObjectArray(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> ElasticsearchException.fromXContent(p), FAILURES);
(p, c) -> OpenSearchException.fromXContent(p), FAILURES);
}

private final int total;
private final int successful;
private final int failed;
private final List<ElasticsearchException> failures;
private final List<OpenSearchException> failures;

public NodesResponseHeader(int total, int successful, int failed, @Nullable List<ElasticsearchException> failures) {
public NodesResponseHeader(int total, int successful, int failed, @Nullable List<OpenSearchException> failures) {
this.total = total;
this.successful = successful;
this.failed = failed;
Expand Down Expand Up @@ -100,7 +100,7 @@ public int getSuccessful() {
*
* @return Never {@code null}. Can be empty.
*/
public List<ElasticsearchException> getFailures() {
public List<OpenSearchException> getFailures() {
return failures;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.client;

import org.apache.http.HttpEntity;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
Expand Down Expand Up @@ -231,14 +231,14 @@
* The majority of the methods in this class come in two flavors, a blocking and an asynchronous version (e.g.
* {@link #search(SearchRequest, RequestOptions)} and {@link #searchAsync(SearchRequest, RequestOptions, ActionListener)}, where the later
* takes an implementation of an {@link ActionListener} as an argument that needs to implement methods that handle successful responses and
* failure scenarios. Most of the blocking calls can throw an {@link IOException} or an unchecked {@link ElasticsearchException} in the
* failure scenarios. Most of the blocking calls can throw an {@link IOException} or an unchecked {@link OpenSearchException} in the
* following cases:
*
* <ul>
* <li>an {@link IOException} is usually thrown in case of failing to parse the REST response in the high-level REST client, the request
* times out or similar cases where there is no response coming back from the Elasticsearch server</li>
* <li>an {@link ElasticsearchException} is usually thrown in case where the server returns a 4xx or 5xx error code. The high-level client
* then tries to parse the response body error details into a generic ElasticsearchException and suppresses the original
* <li>an {@link OpenSearchException} is usually thrown in case where the server returns a 4xx or 5xx error code. The high-level client
* then tries to parse the response body error details into a generic OpenSearchException and suppresses the original
* {@link ResponseException}</li>
* </ul>
*
Expand Down Expand Up @@ -1686,7 +1686,7 @@ public void onFailure(Exception exception) {
}

/**
* Converts a {@link ResponseException} obtained from the low level REST client into an {@link ElasticsearchException}.
* 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 no response body was returned or anything goes wrong while parsing the error, returns a new {@link ElasticsearchStatusException}
* that wraps the original {@link ResponseException}. The potential exception obtained while parsing is added to the returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.elasticsearch.client.indices;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse;
import org.elasticsearch.common.Nullable;
Expand Down Expand Up @@ -90,7 +90,7 @@ public static class IndexResult {
PARSER.declareObject(optionalConstructorArg(), (p, c) -> {
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, p.currentToken(), p);
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p);
Exception e = ElasticsearchException.failureFromXContent(p);
Exception e = OpenSearchException.failureFromXContent(p);
XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, p.nextToken(), p);
return e;
}, new ParseField("exception"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
package org.elasticsearch.client.tasks;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
Expand All @@ -30,7 +31,7 @@

/**
* client side counterpart of server side
* {@link org.elasticsearch.ElasticsearchException}
* {@link OpenSearchException}
* It wraps the same content but it is not throwable.
*/
public class ElasticsearchException {
Expand Down Expand Up @@ -215,7 +216,7 @@ public int hashCode() {

@Override
public String toString() {
return "ElasticsearchException{" +
return "OpenSearchException{" +
"msg='" + msg + '\'' +
", cause=" + cause +
", headers=" + headers +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.client;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
Expand Down Expand Up @@ -129,7 +129,7 @@ public void testClusterUpdateSettingNonExistent() {
ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = new ClusterUpdateSettingsRequest();
clusterUpdateSettingsRequest.transientSettings(Settings.builder().put(setting, value).build());

ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(clusterUpdateSettingsRequest,
OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(clusterUpdateSettingsRequest,
highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync));
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(exception.getMessage(), equalTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.client;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.DocWriteResponse;
Expand Down Expand Up @@ -119,7 +119,7 @@ public void testDelete() throws IOException {
highLevelClient().index(
new IndexRequest("index").id( docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT);
DeleteRequest deleteRequest = new DeleteRequest("index", docId).setIfSeqNo(2).setIfPrimaryTerm(2);
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync));
assertEquals(RestStatus.CONFLICT, exception.status());
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, reason=[" + docId + "]: " +
Expand Down Expand Up @@ -295,7 +295,7 @@ public void testSourceDoesNotExist() throws IOException {
public void testGet() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "id");
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]", exception.getMessage());
Expand All @@ -308,7 +308,7 @@ public void testGet() throws IOException {
highLevelClient().index(index, RequestOptions.DEFAULT);
{
GetRequest getRequest = new GetRequest("index", "id").version(2);
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
assertEquals(RestStatus.CONFLICT, exception.status());
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, " + "reason=[id]: " +
Expand Down Expand Up @@ -488,7 +488,7 @@ public void testMultiGetWithTypes() throws IOException {
public void testGetSource() throws IOException {
{
GetSourceRequest getRequest = new GetSourceRequest("index", "id");
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(getRequest, highLevelClient()::getSource, highLevelClient()::getSourceAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]", exception.getMessage());
Expand All @@ -509,7 +509,7 @@ public void testGetSource() throws IOException {
}
{
GetSourceRequest getRequest = new GetSourceRequest("index", "does_not_exist");
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(getRequest, highLevelClient()::getSource, highLevelClient()::getSourceAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
assertEquals("Elasticsearch exception [type=resource_not_found_exception, " +
Expand Down Expand Up @@ -543,7 +543,7 @@ public void testGetSource() throws IOException {
{
GetSourceRequest getRequest = new GetSourceRequest("index", "id");
getRequest.fetchSourceContext(new FetchSourceContext(false));
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(getRequest, highLevelClient()::getSource, highLevelClient()::getSourceAsync));
assertEquals("Elasticsearch exception [type=action_request_validation_exception, " +
"reason=Validation Failed: 1: fetching source can not be disabled;]", exception.getMessage());
Expand Down Expand Up @@ -1203,7 +1203,7 @@ public void testTermvectors() throws IOException {
public void testTermvectorsWithNonExistentIndex() {
TermVectorsRequest request = new TermVectorsRequest("non-existent", "non-existent");

ElasticsearchException exception = expectThrows(ElasticsearchException.class,
OpenSearchException exception = expectThrows(OpenSearchException.class,
() -> execute(request, highLevelClient()::termvectors, highLevelClient()::termvectorsAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
}
Expand Down
Loading

0 comments on commit ccceb38

Please sign in to comment.