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

SOLR-15749: Create v2 equivalent for 'rename' collection API #1080

Conversation

AAnakhe
Copy link
Contributor

@AAnakhe AAnakhe commented Oct 15, 2022

https://issues.apache.org/jira/browse/SOLR-15749

Description

Create a v2 equivalent of v1 'RENAME' /solr/admin/collections endpoint

Solution

Created a RenameClusterAPI class and RenameClusterPayload class with an endpoint @endpoint(path ={"/clusters/rename/{cluster}"}, method = POST, permission = COLL_EDIT_PERM)

Tests

Tested mapping to API endpoint

Checklist

Please review the following and check all that apply:

  • [√] I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • [√] I have created a Jira issue and added the issue ID to my pull request title.
  • [√] I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • [√] I have developed this patch against the main branch.
  • [√] I have run ./gradlew check.
  • [√] I have added tests for my changes.
  • [] I have added documentation for the Reference Guide

@AAnakhe AAnakhe changed the title SOLR 15749 created a v2 equivalent of v1 'rename' #1061 SOLR 15749 created a v2 equivalent of v1 'rename' Oct 15, 2022
@sonatype-lift
Copy link

sonatype-lift bot commented Oct 15, 2022

⚠️ 314 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @AAnakhe !

I left a few comments on things that'll need fixed, along with hopefully some help for the test issue you mentioned in JIRA! Lmk what you think when you get a chance to read through!

• Renamed, RenameClusterAPI class to RenameCollectionAPI and corresponding implementations

• Renamed, RenameClusterPayload class to RenameCollectionPayload

• Removed V2ClusterAPIMappingTest class and implemented test method in existing V2CollectionAPIMappingTest

• Added apache copyright header to all classes

Result: Test passed
Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

Hey Anakhe - added a few more comments (or follow-ups to comments from my previous review). Let me know if there's any that you need more clarification on, etc.

@AAnakhe
Copy link
Contributor Author

AAnakhe commented Oct 31, 2022 via email

Test result returns  java.lang.AssertionError: expected:<rename> but was:<null>
final SolrParams v1Params = captureConvertedV1Params(
"/collections/collName", "POST", "{\"rename\": {\"to\": \"targetColl\"}}");
public void testRenameCollectionAllParams(){
final SolrQueryRequest request = runRenameCollectionsApi("/collections/collName");
Copy link
Contributor

@joshgog joshgog Nov 1, 2022

Choose a reason for hiding this comment

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

Test result returns java.lang.AssertionError: expected:<rename> but was:<null>

What if we mock SolrQueryRequest and SolrQueryResponse , pass them to thepublic void renameCollection(SolrQueryRequest req, SolrQueryResponse rsp) method of the API then perform the assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try to implement that, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test result returns java.lang.AssertionError: expected:<rename> but was:<null>

What if we mock SolrQueryRequest and SolrQueryResponse , pass them to thepublic void renameCollection(SolrQueryRequest req, SolrQueryResponse rsp) method of the API then perform the assertions

Please I need more clarification on this

Copy link
Contributor

@joshgog joshgog Nov 1, 2022

Choose a reason for hiding this comment

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

I'm not sure what exactly you would like to be clarified. If its about mocks checkout AddReplicaPropertyAPITest which uses mocked SolrQueryRequest and SolrQueryResponse

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to what Josh said. AddReplicaPropertyAPITest is a good example on how to use mocks, but it's setup for APIs that use the JAX-RS framework, so you wouldn't want to follow it too closely. But it's good if you're just looking for an example on the mock stuff.

And I'm sure we'd both be happy to clarify if you can elaborate a bit on what you need clarified.

[Q] One thing that jumps out at me on this line is the runRenameCollectionsAPI: is there a reason you've created a separate method for this instead of reusing one of the captureConvertedV1Params methods that's already out there. If there's not some reason for runRenameCollectionsAPI that I'm missing, you could presumably just replace its usage here with a snippet like:

    final SolrParams v1Params = captureConvertedV1Params("/collections/collName/commands/rename", "POST",
            "{\"to\": \"targetColl\", \"async\": \"requestTrackingId\", \"followAliases\": true}");

The second thing that jumps out at me here is the path being sent as an argument to this method - it doesn't match the path of the API you created in this PR (see here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought you said we were moving away from the old captureConvertedV1Params syntax, I wasn't aware there are different method implementations

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, not quite. Or at least, I didn't mean to suggest that?

What I probably meant to say is that Solr is moving away from its traditional v2 API framework to a framework based on JAX-RS. captureConvertedV1Params is a nice utility for testing APIs implemented using the "traditional" (i.e. non JAX-RS) framework.

In the long run I'd expect to see usage of captureConvertedV1Params decline, but not because it's deprecated or shouldn't be used - just because things will switch over to JAX-RS as time goes by. This PR uses the traditional framework (which is absolutely still valid), so it's fine/normal to use captureConvertedV1Params in your tests.

I'll push up a commit here to help get the unit test over the line and then hopefully we can get this merged 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's clearer now, and I'm so glad to hear that this will be merged thank you.

Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

Going through some of my reviews this afternoon just to summarize a bit where things stand:

There are a few small bugs in this PR that I've added line-level comments for: mostly small stuff. Other than those, the only outstanding issue is getting that V2CollectionAPIMappingTest unit test passing. I'll give you a little more time to respond to Josh's and my suggestions there (see the line-level comments on that file), but I'll try to take a look at the test myself next week to see if there's any obvious issue we can help you through.

Enjoy your weekend!

final SolrParams v1Params = captureConvertedV1Params(
"/collections/collName", "POST", "{\"rename\": {\"to\": \"targetColl\"}}");
public void testRenameCollectionAllParams(){
final SolrQueryRequest request = runRenameCollectionsApi("/collections/collName");
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to what Josh said. AddReplicaPropertyAPITest is a good example on how to use mocks, but it's setup for APIs that use the JAX-RS framework, so you wouldn't want to follow it too closely. But it's good if you're just looking for an example on the mock stuff.

And I'm sure we'd both be happy to clarify if you can elaborate a bit on what you need clarified.

[Q] One thing that jumps out at me on this line is the runRenameCollectionsAPI: is there a reason you've created a separate method for this instead of reusing one of the captureConvertedV1Params methods that's already out there. If there's not some reason for runRenameCollectionsAPI that I'm missing, you could presumably just replace its usage here with a snippet like:

    final SolrParams v1Params = captureConvertedV1Params("/collections/collName/commands/rename", "POST",
            "{\"to\": \"targetColl\", \"async\": \"requestTrackingId\", \"followAliases\": true}");

The second thing that jumps out at me here is the path being sent as an argument to this method - it doesn't match the path of the API you created in this PR (see here).

@AAnakhe
Copy link
Contributor Author

AAnakhe commented Nov 4, 2022 via email

AAnakhe and others added 4 commits November 8, 2022 03:53
Test failed: java.lang.NullPointerException: Cannot invoke "java.lang.Iterable.iterator()" because the return value of "org.apache.solr.request.SolrQueryRequest.getContentStreams()" is null
Includes fix for V2CollectionAPIMappingTest
This at least adds a corresponding v2 snippet.

Note that this section of the ref-guide is missing several parameters
that the API does support.  Ideally we'd backfill these, but I've held
off here out of healthy respect for scope creep.
Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

Alright, I've added a few commits to this PR to help move things along.

Most of it is cleanup, with the exception of a small test fix in V2CollectionAPIMappingTest, and some ref-guide coverage for the new v2 API. Take a look at the new commits if you're curious.

I think this should be ready for merge now, once the tests and 'check' pass. If anyone else sees anything I'm missing, lmk!

build.gradle Outdated
@@ -207,5 +207,5 @@ apply from: file('gradle/ant-compat/solr.post-jar.gradle')

apply from: file('gradle/node.gradle')

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
//sourceCompatibility = JavaVersion.VERSION_16_PREVIEW
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] Ooh, interesting. Did you intend to edit these lines @AAnakhe ?

A few months back I inadvertently committed changes to these two lines, but to this day I have no memory of editing them. I suspected it came from importing into my IDE or some similar operation but I never was able to figure out what did it.

Anyway, just curious if you intended these changes here. And if you didn't, if you had any guesses what might've edited them on your behalf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't intend to make any changes there, it was imported by my IDE when I clicked on a confirmation request from IntelliJ requesting support for Java 16 or so, I can not recall correctly

.disable(MapperFeature.AUTO_DETECT_FIELDS);

@EndPoint(
path = {"/collections/{collection}/commands/rename"},
Copy link
Contributor

Choose a reason for hiding this comment

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

[0] There was some discussion on a different v2 API PR about the /commands path segment in this path, and the consensus was that we should drop that path segment.

I'll update the code here accordingly.

@gerlowskija gerlowskija changed the title SOLR 15749 created a v2 equivalent of v1 'rename' SOLR-15749: Create v2 equivalent for 'rename' collection API Nov 9, 2022
@gerlowskija gerlowskija merged commit ed93594 into apache:main Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants