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

[CCI] [Extensions] Added the ExtensionActionUtil class #6969

Merged
merged 17 commits into from
Jun 21, 2023

Conversation

Kuanysh-kst
Copy link
Contributor

@Kuanysh-kst Kuanysh-kst commented Apr 4, 2023

Description

In this PR, I add methods to the ExtensionActionUtil class to reduce code repetition

Issues Resolved

opensearch-project/opensearch-sdk-java#607

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

Gradle Check (Jenkins) Run Completed with:

@dblock
Copy link
Member

dblock commented Apr 4, 2023

Needs tests please.

@Kuanysh-kst Kuanysh-kst changed the title Adding the ExtensionActionUtil class [Extensions]Adding the ExtensionActionUtil class Apr 5, 2023
@Kuanysh-kst
Copy link
Contributor Author

@dbwiddis why when I want to run Junit test I get an error: Caused by: java.io.EOFException: tried to read: 101 bytes but this stream is limited to: 7
This error occurs when I need to create a new Extension Action Request object in this line:

   actionRequest = (ActionRequest) constructor.newInstance(requestByteStream);

and as I understood that the error occurs when comparing the length of a new byte array and the unicode of the first byte
here is the error path:

Caused by: java.io.EOFException: tried to read: 101 bytes but this stream is limited to: 7
	at org.opensearch.common.io.stream.InputStreamStreamInput.ensureCanReadBytes(InputStreamStreamInput.java:137)
	at org.opensearch.common.io.stream.StreamInput.readArraySize(StreamInput.java:1310)
	at org.opensearch.common.io.stream.StreamInput.readString(StreamInput.java:420)
	at org.opensearch.tasks.TaskId.readFromStream(TaskId.java:96)
	at org.opensearch.transport.TransportRequest.<init>(TransportRequest.java:71)
	at org.opensearch.action.ActionRequest.<init>(ActionRequest.java:56)
	at org.opensearch.extensions.action.ExtensionActionRequest.<init>(ExtensionActionRequest.java:52)

here is a test version of the test that throws an error:

            @Test
            public void testCreateActionRequest() throws IOException {
            String action = "example";
            ExtensionActionRequest request = new ExtensionActionRequest(action, action.getBytes(StandardCharsets.UTF_8));

            byte[] array = ExtensionActionUtil.createProxyRequestBytes(request);
            ExtensionActionRequest request1 = new ExtensionActionRequest(action,array);

            ActionRequest actionRequest = ExtensionActionUtil.createActionRequest(request1);
            assertNotNull(actionRequest);

    }

@Kuanysh-kst
Copy link
Contributor Author

I solved it by adding this code to test:

        String action = "abc" ;
        int length = 10;
        byte lengthByte = (byte) (length & 0xff);

        byte[] requestClass = ExtensionActionRequest.class.getName().getBytes();
        System.out.println("cl: "+requestClass.length+ "+1+"+action.getBytes().length);
        byte[] result = ByteBuffer.allocate(requestClass.length + 2 + action.codePointAt(0))
            .put(requestClass)
            .put(UNIT_SEPARATOR)
            .put(lengthByte)
            .put(action.getBytes(StandardCharsets.UTF_8))
            .array();

with this code I set the length for the byte array:
byte lengthByte = (byte) (length & 0xff);

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@Kuanysh-kst Kuanysh-kst requested a review from dbwiddis June 1, 2023 16:08
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

Gradle Check (Jenkins) Run Completed with:

@Kuanysh-kst Kuanysh-kst changed the title [CCI] [Extensions] Adding the ExtensionActionUtil class [CCI] [Extensions] Added the ExtensionActionUtil class Jun 1, 2023
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

Gradle Check (Jenkins) Run Completed with:

@Kuanysh-kst
Copy link
Contributor Author

@owaiskazi19 , @ryanbogan can you check this PR

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dbwiddis dbwiddis added skip-changelog backport 2.x Backport to 2.x branch labels Jun 10, 2023
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@dbwiddis
Copy link
Member

Gradle check failure is a bwc bug since fixed. Please rebase to main to get gradle check to pass.

@Kuanysh-kst Kuanysh-kst requested a review from sachinpkale as a code owner June 21, 2023 18:30
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      2 org.opensearch.cluster.service.MasterServiceTests.classMethod
      1 org.opensearch.cluster.service.MasterServiceTests.testThrottlingForMultipleTaskTypes

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Merging #6969 (c78d52c) into main (68c1c86) will decrease coverage by 0.18%.
The diff coverage is 87.09%.

@@             Coverage Diff              @@
##               main    #6969      +/-   ##
============================================
- Coverage     70.93%   70.76%   -0.18%     
+ Complexity    56636    56534     -102     
============================================
  Files          4719     4720       +1     
  Lines        267559   267590      +31     
  Branches      39206    39208       +2     
============================================
- Hits         189805   189350     -455     
- Misses        61714    62243     +529     
+ Partials      16040    15997      -43     
Impacted Files Coverage Δ
...nsearch/extensions/action/ExtensionActionUtil.java 87.09% <87.09%> (ø)

... and 494 files with indirect coverage changes

@dbwiddis dbwiddis merged commit 2d9a88c into opensearch-project:main Jun 21, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 21, 2023
* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* added new name to tests

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test class renaming

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

---------

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
(cherry picked from commit 2d9a88c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
gaiksaya pushed a commit to gaiksaya/OpenSearch that referenced this pull request Jun 21, 2023
…oject#6969)

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* added new name to tests

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test class renaming

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

---------

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
imRishN pushed a commit to imRishN/OpenSearch that referenced this pull request Jun 27, 2023
…oject#6969)

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* added new name to tests

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test class renaming

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

---------

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
Signed-off-by: Rishab Nahata <rnnahata@amazon.com>
kotwanikunal pushed a commit that referenced this pull request Jul 13, 2023
* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* added new name to tests

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test class renaming

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

---------

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
(cherry picked from commit 2d9a88c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
shiv0408 pushed a commit to Gaurav614/OpenSearch that referenced this pull request Apr 25, 2024
…oject#6969)

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtill class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add ExtensionActionUtilTest class

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add method convertParamsToBytes

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* added new name to tests

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test code refactoring

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

* test class renaming

Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>

---------

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>
Signed-off-by: Kuanysh <90975457+Kuanysh-kst@users.noreply.github.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants