Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] OpenSearchIndicesClient#getAlias throws UnexpectedJsonEventException when the alias doesn't exist #301

Closed
luontola opened this issue Dec 22, 2022 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@luontola
Copy link

luontola commented Dec 22, 2022

What is the bug?

When specifying the name of an alias with org.opensearch.client.opensearch.indices.GetAliasRequest.Builder#name and the alias doesn't exist on the server, the client will throw a JSON parsing exception instead of indicating that the alias doesn't exist.

How can one reproduce the bug?

Run the following code when the foo alias doesn't exist.

        OpenSearchClient client = new OpenSearchClient(
                new RestClientTransport(
                        RestClient.builder(HttpHost.create("http://127.0.0.1:9200"))
                                .build(),
                        new JacksonJsonpMapper()));

        try (var ignored = client._transport()) {
            GetAliasResponse response = client.indices().getAlias(
                    builder -> builder.name("foo")
            );
            System.out.println(response.result());
        }

The client will make the request GET /_alias/foo and the server will response with http status 404 and the body {"error":"alias [foo] missing","status":404}.

This causes the client to throw the exception:

org.opensearch.client.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_STRING' instead of '[START_OBJECT, KEY_NAME]'
	at org.opensearch.client.json.JsonpUtils.ensureAccepts(JsonpUtils.java:81)
	at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:87)
	at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:92)
	at org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:56)
	at org.opensearch.client.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:85)
	at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:189)
	at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:150)
	at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:88)
	at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:92)
	at org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:56)
	at org.opensearch.client.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:271)
	at org.opensearch.client.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:143)
	at org.opensearch.client.opensearch.indices.OpenSearchIndicesClient.getAlias(OpenSearchIndicesClient.java:671)
	at org.opensearch.client.opensearch.indices.OpenSearchIndicesClient.getAlias(OpenSearchIndicesClient.java:685)
	at example.Example.main(Example.java:30)

What is the expected behavior?

It would return a result that says the alias doesn't exist. I suppose with the current Java client the style is to throw an OpenSearchException with status 404.

What is your host/environment?

opensearch server 2.3.0
opensearch-java 2.1.0
opensearch-rest-client 2.4.0

@luontola luontola added bug Something isn't working untriaged labels Dec 22, 2022
@wbeckler
Copy link

This is a good catch. Would you be up for writing a PR to fix this, or at least a failing test?

@wbeckler wbeckler added the good first issue Good for newcomers label Jan 4, 2023
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue Mar 7, 2023
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue Mar 7, 2023
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue Mar 7, 2023
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue Mar 7, 2023
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue Mar 30, 2023
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue May 10, 2023
VachaShah pushed a commit that referenced this issue May 10, 2023
…#476)

* fix: handle String error deserialization for ErrorCause object (#301)

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* update CHANGELOG.md

Signed-off-by: Dominik Szczepanczyk <[email protected]>

---------

Signed-off-by: Dominik Szczepanczyk <[email protected]>
szczepanczykd added a commit to szczepanczykd/opensearch-java that referenced this issue May 11, 2023
…earch-project#301) (opensearch-project#476)

* fix: handle String error deserialization for ErrorCause object (opensearch-project#301)

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* update CHANGELOG.md

Signed-off-by: Dominik Szczepanczyk <[email protected]>

---------

Signed-off-by: Dominik Szczepanczyk <[email protected]>
VachaShah pushed a commit that referenced this issue May 11, 2023
…#476) (#478)

* fix: handle String error deserialization for ErrorCause object (#301)



* update CHANGELOG.md



---------

Signed-off-by: Dominik Szczepanczyk <[email protected]>
@szczepanczykd
Copy link
Collaborator

The fix should be available in version 2.5.0.

For now, You can use a snapshot containing this fix:
https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/client/opensearch-java/2.5.0-SNAPSHOT/opensearch-java-2.5.0-20230511.172333-5.jar

dblock pushed a commit that referenced this issue May 23, 2023
* fix: handle String error deserialization for ErrorCause object (#301) (#476)

* fix: handle String error deserialization for ErrorCause object (#301)

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* update CHANGELOG.md

Signed-off-by: Dominik Szczepanczyk <[email protected]>

---------

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* fix: change int type to long (#489)

* fix: change int type to long

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* update CHANGELOG.md

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* fix: change totalDataSetSizeInBytes to Long too

Signed-off-by: Dominik Szczepanczyk <[email protected]>

* fix: skip removing opensearch-observability index in AfterTest cleanup

Signed-off-by: Dominik Szczepanczyk <[email protected]>

---------

Signed-off-by: Dominik Szczepanczyk <[email protected]>

---------

Signed-off-by: Dominik Szczepanczyk <[email protected]>
@szczepanczykd
Copy link
Collaborator

Fixed in 2.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants