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

blog post: Using the resteasy-grpc feature together with the WildFly … #129

Merged
merged 6 commits into from
Sep 12, 2023

Conversation

liweinan
Copy link
Contributor

@liweinan liweinan commented Aug 7, 2023

…gRPC subsystem

@liweinan liweinan self-assigned this Aug 7, 2023
@liweinan
Copy link
Contributor Author

liweinan commented Aug 7, 2023

@jamezp @ronsigal I have finished writing this blog post finally, could you please help to review this when you have time? Thanks!

@jamezp
Copy link
Contributor

jamezp commented Aug 7, 2023

I'll give this a read and follow the instructions, hopefully, a little later today.

@liweinan
Copy link
Contributor Author

liweinan commented Aug 8, 2023

@jamezp Thanks!

@ronsigal
Copy link
Contributor

ronsigal commented Aug 8, 2023

Heyyy @liweinan,

I'm so happy!! You have resteasy-grpc number 1!! [See https://en.wikipedia.org/wiki/Erd%C5%91s_number] :)

Here are a couple of notes:

  1. I would change the first sentence to something like: "resteasy-grpc is a project that can help you to generate a bridge project that can expose REST service APIs to gRPC clients." I think it has a little more punch.

  2. I would change "(And part of the code is generated from the .proto file generated by the gRPC" to " (And part of the code is generated from the .proto file by the gRPC".

  3. I would change

Note: Among these generated classes, the Greet_Server will start a standalone gRPC server, which is backend by the standard io.grpc server. However the WildFly server has its own gRPC subsystem, and it will automatically detect our gRPC bridge project and start a gRPC service at port 9990, so we won’t use this class in this article.

to something like

Note: Among these generated classes, the Greet_Server class has a method startGRPC() which can start a standalone gRPC server, which is backed by the standard io.grpc server. However the WildFly server has its own gRPC subsystem, and it will automatically detect our gRPC bridge project and start a gRPC service at port 9990, so we won’t use this method in this article. We will, however, use the startContext() method.

  1. I really like the paragraph starting "The deployment will do two things:". I've never said that so clearly and succinctly.

Well done!! Thank you!!

@liweinan
Copy link
Contributor Author

liweinan commented Aug 9, 2023

@ronsigal Thanks for the praising ! I'll modify the contents as you suggested :D

Comment on lines 55 to 67
```bash
$ mvn archetype:generate -B \
-DarchetypeGroupId=dev.resteasy.grpc \
-DarchetypeArtifactId=gRPCtoJakartaREST-archetype \
-DarchetypeVersion=1.0.0.Alpha5 \
-DgroupId=dev.resteasy.examples \
-DartifactId=grpcToRest.example \
-Dversion=1.0.1.Final-SNAPSHOT \
-Dgenerate-prefix=Greet \
-Dgenerate-package=org.greet \
-Dresteasy-version=6.2.4.Final \
-Dgrpc-bridge-version=1.0.0.Alpha2
```
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not work for me. I see this:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< dev.resteasy.examples:grpcToRest.example >--------------
[INFO] Building gRPC to Jakarta REST example 1.0.1.Final-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] >>> archetype:3.1.2:generate (default-cli) > generate-sources @ grpcToRest.example >>>
[INFO] 
[INFO] --- enforcer:3.0.0-M3:enforce (enforce-java-version) @ grpcToRest.example ---
[INFO] 
[INFO] --- enforcer:3.0.0-M3:enforce (enforce-maven-version) @ grpcToRest.example ---
[INFO] 
[INFO] --- buildnumber:1.4:create (get-scm-revision) @ grpcToRest.example ---
[INFO] Executing: /bin/sh -c cd '/home/jperkins/projects/resteasy/resteasy-examples/grpc-bridge-example' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/jperkins/projects/resteasy/resteasy-examples/grpc-bridge-example
[INFO] Storing buildNumber: d14fb2264adacc704b20a5d9f3d709fc74ab5e35 at timestamp: 1691610063655
[INFO] Storing buildScmBranch: main
[INFO] 
[INFO] <<< archetype:3.1.2:generate (default-cli) < generate-sources @ grpcToRest.example <<<
[INFO] 
[INFO] 
[INFO] --- archetype:3.1.2:generate (default-cli) @ grpcToRest.example ---
[INFO] Generating project in Batch mode
[INFO] Archetype repository not defined. Using the one from [dev.resteasy.grpc:gRPCtoJakartaREST-archetype:1.0.0.Alpha5] found in catalog remote
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: gRPCtoJakartaREST-archetype:1.0.0.Alpha5
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dev.resteasy.examples
[INFO] Parameter: artifactId, Value: grpcToRest.example
[INFO] Parameter: version, Value: 1.0.1.Final-SNAPSHOT
[INFO] Parameter: package, Value: dev.resteasy.examples
[INFO] Parameter: packageInPathFormat, Value: dev/resteasy/examples
[INFO] Parameter: package, Value: dev.resteasy.examples
[INFO] Parameter: resteasy-version, Value: 6.2.4.Final
[INFO] Parameter: generate-prefix, Value: Greet
[INFO] Parameter: groupId, Value: dev.resteasy.examples
[INFO] Parameter: artifactId, Value: grpcToRest.example
[INFO] Parameter: grpc-bridge-version, Value: 1.0.0.Alpha2
[INFO] Parameter: generate-package, Value: org.greet
[INFO] Parameter: version, Value: 1.0.1.Final-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.057 s
[INFO] Finished at: 2023-08-09T12:41:07-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate (default-cli) on project grpcToRest.example: Unable to add module to the current project as it is not of packaging type 'pom' -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I think the -Dgenerate-package=org.greet needs to be changed to -Dgenerate-package=dev.resteasy.examples.grpc.greet. However, if I do that it just hangs and fails with the same error.

It does create a new grpcToRest.example directory with a pom.xml file, but I'm not sure what to do with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamezp From the output it seems you are running the above command inside the grpc-bridge-example project directory:

[INFO] Executing: /bin/sh -c cd '/home/jperkins/projects/resteasy/resteasy-examples/grpc-bridge-example' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/jperkins/projects/resteasy/resteasy-examples/grpc-bridge-example

Actually the command should be run in an empty directory:

weli@192:~/w/play-grpc
➤  mvn archetype:generate -B \                                                                                                         22:51:57
               -DarchetypeGroupId=dev.resteasy.grpc \
               -DarchetypeArtifactId=gRPCtoJakartaREST-archetype \
               -DarchetypeVersion=1.0.0.Alpha5 \
               -DgroupId=dev.resteasy.examples \
               -DartifactId=grpcToRest.example \
               -Dversion=1.0.1.Final-SNAPSHOT \
               -Dgenerate-prefix=Greet \
               -Dgenerate-package=org.greet \
               -Dresteasy-version=6.2.4.Final \
               -Dgrpc-bridge-version=1.0.0.Alpha2
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype repository not defined. Using the one from [dev.resteasy.grpc:gRPCtoJakartaREST-archetype:1.0.0.Alpha5] found in catalog remote
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: gRPCtoJakartaREST-archetype:1.0.0.Alpha5
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dev.resteasy.examples
[INFO] Parameter: artifactId, Value: grpcToRest.example
[INFO] Parameter: version, Value: 1.0.1.Final-SNAPSHOT
[INFO] Parameter: package, Value: dev.resteasy.examples
[INFO] Parameter: packageInPathFormat, Value: dev/resteasy/examples
[INFO] Parameter: package, Value: dev.resteasy.examples
[INFO] Parameter: resteasy-version, Value: 6.2.4.Final
[INFO] Parameter: generate-prefix, Value: Greet
[INFO] Parameter: groupId, Value: dev.resteasy.examples
[INFO] Parameter: artifactId, Value: grpcToRest.example
[INFO] Parameter: grpc-bridge-version, Value: 1.0.0.Alpha2
[INFO] Parameter: generate-package, Value: org.greet
[INFO] Parameter: version, Value: 1.0.1.Final-SNAPSHOT
[INFO] Project created from Archetype in dir: /Users/weli/works/play-grpc/grpcToRest.example
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.775 s
[INFO] Finished at: 2023-08-10T22:52:11+08:00
[INFO] ------------------------------------------------------------------------
weli@192:~/w/play-grpc

And in this empty directory the bridge project is generated:

weli@192:~/w/play-grpc
➤ ls -G                                                                                                                                22:52:11
grpcToRest.example

I guess this part of text is not clear on this point, and I'll add some notes to the blog post.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. Yeah, that definitely was clear to me. I'll try this again later today and report back.

FWIW if we do need to run this in a separate project and copy things around, that's not great UX. We should really focus on fixing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes currently the design is that the archetype project copies the Java classes from the "source project" into the "bridge project" via the maven-dependency-plugin(https://github.com/resteasy/gRPCtoJakartaREST-archetype/blob/main/src/main/resources/archetype-resources/pom.xml#L189), and then the resteasy-grpc do the rest of the processing and generation work inside the "bridge project".

Comment on lines 220 to 224
```bash
galleon.sh install wildfly:current --dir=wildfly
galleon.sh install org.jboss.resteasy:galleon-feature-pack:6.2.4.Final --dir=wildfly --ignore-not-excluded-layers=true
galleon.sh install org.wildfly.extras.grpc:wildfly-grpc-feature-pack:0.1.1.Final --layers=grpc --dir=wildfly
```
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should use the wildfly-maven-plugin to provision the container. It can just be provisioned in the target directory and used for the test or with the wildfly:dev goal to do manual testing.

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'll learn how to achieve this and if I have questions I'll ask you for help :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamezp I start to work on using the wildfly-maven-plugin directly, and here is the draft: liweinan/grpcToRest.example#1

In addition, I need to convert the test to use Arquillian for it to work right?

This means the `key-manager` is not set in the `grpc` subsystem, which means it will use `plaintext` to do the gRPC communication. We can confirm this setting is running the following command:

```bash
[standalone@localhost:9990 /] /subsystem=grpc:write-attribute(name=key-manager-name, value="")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be /subsystem=grpc:undefine-attribute(name=key-manager-name).

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually though, this shouldn't be done at all. If this is an issue we need to fix the subsystem itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay! I'll fix the text firstly for now. @jamezp Could you please provide me more information why this is a problem in the subsystem? Guess I can create an issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it says:

This means the key-manager is not set in the grpc subsystem, which means it will use plaintext to do the gRPC communication. We can confirm this setting is running the following command:

If there is no change required, I'm not sure why we'd execute the command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To confirm the default setting(in case I modified it locally), I installed a fresh copy of WildFly with Galleon and here are the default settings:

[standalone@localhost:9990 /] ls subsystem=grpc:read-attribute
flow-control-window=undefined                  max-connection-age-grace=undefined             server-port=9555
handshake-timeout=undefined                    max-connection-idle=undefined                  session-cache-size=undefined
initial-flow-control-window=undefined          max-inbound-message-size=undefined             session-timeout=undefined
keep-alive-time=undefined                      max-inbound-metadata-size=undefined            shutdown-timeout=3
keep-alive-timeout=undefined                   permit-keep-alive-time=undefined               ssl-context-name=undefined
key-manager-name=undefined                     permit-keep-alive-without-calls=undefined      start-tls=undefined
max-concurrent-calls-per-connection=undefined  protocol-provider=undefined                    trust-manager-name=undefined
max-connection-age=undefined                   server-host=localhost

So the key-manager-name by default is undefined. I did the test and it passed:

image

So the attribute actually don't need to be modified. I'll update the both the blog post text and the example source code on this part. Thanks for pointing this out James!

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 have created a PR here: resteasy/resteasy-examples#158

Comment on lines 330 to 334
```bash
➤ curl http://localhost:8080/grpcToRest.example.grpc-1.0.1.Final-SNAPSHOT/grpcToJakartaRest/grpcserver/context

2Got org.greet.Greet_Server@4c9c8c0a servletContext⏎
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we not worked around this yet? I thought we did for some reason.

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'll add a flag to ensure it just initialized once for now. And in the future maybe we'll change the design as discussed with @ronsigal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ronsigal I've added a flag to check the servletContext is just initialized once as we discussed: https://github.com/resteasy/resteasy-grpc/pull/18/files @jamezp I'm not sure if we need to change the design of this part totally, if so could you please provide some help on this? :p

@liweinan
Copy link
Contributor Author

@jamezp Thanks for the review! I'll check the details and do the modifications accordingly. :D

@liweinan
Copy link
Contributor Author

liweinan commented Aug 10, 2023

In addition I find if the project is redeployed the gRPC subsystem is not restart automatically:

image

And I have to restart the WildFly completely for the gRPC server to start. I'm not sure whether this is a design or a bug in the WildFly gRPC subsystem @jamezp @ronsigal

@liweinan
Copy link
Contributor Author

@jamezp Until now all the related changes PRs are merged into the resteasy-grpc and the gRPCtoJakartaREST-archetype projects. Except these tasks are left to do:

IMHO the above issues are more or less inter-related and maybe needs sometime to complete, so can this blog post be published for now, and if there are updates/improvements on the whole workflow in the future, then I provide another blog post?

@jamezp
Copy link
Contributor

jamezp commented Aug 15, 2023

IMHO it would be nice to get these things fixed so the blog can show a good user experience. I need to walk through it again, which I can probably do today, so I can see how the steps work.

I really think we have too many moving parts and we need to make this easier for the end user.

@liweinan
Copy link
Contributor Author

@jamezp Thanks for help on this!

@ronsigal
Copy link
Contributor

ronsigal commented Aug 15, 2023

I find if the project is redeployed the gRPC subsystem is not restart automatically:

I'm not sure why the subsystem should be restarted. Isn't it enough that the new deployment is detected and added to the server? Well, I guess the subsystem should be able to remove the old version of the deployment.

@ronsigal
Copy link
Contributor

we need to make this easier for the end user.

definitely

@liweinan
Copy link
Contributor Author

I find if the project is redeployed the gRPC subsystem is not restart automatically:

I'm not sure why the subsystem should be restarted. Isn't it enough that the new deployment is detected and added to the server? Well, I guess the subsystem should be able to remove the old version of the deployment.

Sorry my description may not be very accurate. The situation is: After the bridge project is redeployed, then the gRPC subsystem stop services at port 9555, and I have to restart the whole WildFly server for it to work again.

@jamezp
Copy link
Contributor

jamezp commented Aug 16, 2023

I find if the project is redeployed the gRPC subsystem is not restart automatically:

I'm not sure why the subsystem should be restarted. Isn't it enough that the new deployment is detected and added to the server? Well, I guess the subsystem should be able to remove the old version of the deployment.

Sorry my description may not be very accurate. The situation is: After the bridge project is redeployed, then the gRPC subsystem stop services at port 9555, and I have to restart the whole WildFly server for it to work again.

That sounds lie a bug. The server should not be stopping on undeploy. I did rework the subsystem, I wonder if we need a new release.

@liweinan
Copy link
Contributor Author

I find if the project is redeployed the gRPC subsystem is not restart automatically:

I'm not sure why the subsystem should be restarted. Isn't it enough that the new deployment is detected and added to the server? Well, I guess the subsystem should be able to remove the old version of the deployment.

Sorry my description may not be very accurate. The situation is: After the bridge project is redeployed, then the gRPC subsystem stop services at port 9555, and I have to restart the whole WildFly server for it to work again.

That sounds lie a bug. The server should not be stopping on undeploy. I did rework the subsystem, I wonder if we need a new release.

+1

@ronsigal
Copy link
Contributor

After the bridge project is redeployed, then the gRPC subsystem stop services at port 9555, and I have to restart the whole WildFly server for it to work again.

Ah, I see. Yeah, that's not right.

@liweinan
Copy link
Contributor Author

@jamezp I have updated the date of the blog post. Please let me know if anything else need to be modified :D

@jamezp jamezp merged commit 3fdcf1f into resteasy:main Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants