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

WildFly mini series: REST Client #671

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tommaso-borgato
Copy link
Contributor

@tommaso-borgato tommaso-borgato commented Oct 17, 2024

This PR contains 3 more guides to be added to the Java Microservices on Kubernetes with WildFly:

  1. HOW-TO invoke one microservice from another microservice
  2. HOW-TO to do it on Kubernetes
  3. HOW-TO to propagate security data

wildfly-extras/guides#4 contains the source code for all the 3 new guides

#676 contains a proposal on HOW-TO re-organize the whole "WildFly mini series" contents

Fixes #687

@tommaso-borgato
Copy link
Contributor Author

tommaso-borgato commented Nov 7, 2024

@bstansberry can you assign a reviewer for this one?

Also wildfly-extras/guides#4 would need a reviewer ...

@asoldano asoldano requested a review from jamezp November 7, 2024 10:36
@asoldano
Copy link
Contributor

asoldano commented Nov 7, 2024

As this involves REST Client, I think @jamezp might want to review

@jamezp
Copy link
Member

jamezp commented Nov 7, 2024

I'll try to have a look this week or early next week. I've got to get a RESTEasy release out, so once that's done I should have some time.

Copy link
Member

@jamezp jamezp left a comment

Choose a reason for hiding this comment

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

I've had to stop the process of checking this on the second part as it's not working for me.

@@ -3,13 +3,14 @@
:jaxrs-example-project-artifactId: jaxrs
:jaxrs-example-project-version: 11.0.0.Final-SNAPSHOT
:version-bootable-jar: 11.0.0.Beta1
:version-wildfly: 32.0.0.Final
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using WildFly 32? Shouldn't we use WildFly 34?


@RegisterRestClient(configKey="simple-microservice-server")
@Path("/hello")
public interface GettingStartedEndpointInterface {
Copy link
Member

Choose a reason for hiding this comment

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

IMO we should name this something like GettingStartedClient or GettingStartedEndpointClient.

Comment on lines 49 to 52
* remove folder *src/test*
* remove all test scope dependencies

NOTE: we remove tests in preparation for the upcoming guides
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow this and it seems a bit odd to me.

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 changed the wording ... I was basically trying to say that the tests that were included with the archetype wouldn't be relevant anymore since we are using service to service invocation


==== pom.xml

Set `<artifactId>simple-microservice-server</artifactId>`;
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to be more descriptive here and state something like:

Update the artifactId to <artifactid>simple-microservice-server</artifactId>.

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 tnks, changed

Comment on lines 71 to 78
Since you copied {source-code-git-repository}/simple-microservice[simple-microservice], the Dockerfile from link:https://github.com/wildfly/wildfly-s2i/blob/main/examples/docker-build/Dockerfile[examples/docker-build/Dockerfile, window="_blank"] should already be at the root of your project;

==== Build the Docker Image

[source,bash,subs="normal"]
----
podman build -t {my-jaxrs-app-docker-image-name-server}:latest .
----
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we don't use the wildfly-maven-plugin to generate the Dockerfile/image?

Copy link
Contributor Author

@tommaso-borgato tommaso-borgato Nov 28, 2024

Choose a reason for hiding this comment

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

@jamezp thank you for the suggestion ... if you agree I'll add a note that tells about this option (https://docs.wildfly.org/wildfly-maven-plugin/releases/5.1/image-mojo.html) ... throughout the guides I tried to keep it stupid simple and just use the minimal set of tools/configurations the user might be already familiar with ... for example I didn't use glow ... my fear is that the reader might abandon the reading if feeling overwhelmed with too many tools/configurations ... I also wanted to show what's going on under the hood to show it's actually simple stuff

----
podman run --rm -p 8080:8080 -p 9990:9990 \
--network={podman-network-name} \
--env "SIMPLE_MICROSERVICE_SERVER_URI=http://{my-jaxrs-app-docker-image-name-server}:8080/hello" \
Copy link
Member

Choose a reason for hiding this comment

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

The hello needs to be removed at the end since the GettingStartedEndpointInterface includes @Path("/hello").

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 great catch! Thank you


=== Deploy on Kubernetes

Create a file named `{my-jaxrs-app-docker-image-name-server}-deployment.yaml`:
Copy link
Member

Choose a reason for hiding this comment

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

Where do I create this file? I assume in simple-microservice-server.

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 added instructions on where to create kubernetes files


[source,bash,subs="normal"]
----
kubectl apply -f {my-jaxrs-app-docker-image-name-server}-deployment.yaml
Copy link
Member

Choose a reason for hiding this comment

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

This fails if Kubernetes is not running. We should add a step for minikube start.


=== Create Kubernetes ClusterIP Service

We create a service to consume the services exposed by **{my-jaxrs-app-docker-image-name-server}** from inside Kubernetes;
Copy link
Member

Choose a reason for hiding this comment

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

Again, I assume this needs to happen in the client, but it's not really described. Or I guess in any directory, but seems it should specify.

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 added a link to https://kubernetes.io/docs/concepts/services-networking/service/ which should clarify this statement


[source,bash,subs="normal"]
----
kubectl run --rm -it --tty curl-{my-jaxrs-app-docker-image-name-server} --image=curlimages/curl --restart=Never &dash;&dash; {my-jaxrs-app-docker-image-name-server}-service:8080/hello/pippo
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work for me. It's possible I don't have minikube started correctly. I just did minikube start.

If you don't see a command prompt, try pressing enter.
curl: (6) Could not resolve host: xxx
Hello 'pippo'.pod "curl-my-jaxrs-app-server" deleted

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 just deleted and re-installed a fresh minikube .... perhaps the two dashed get copied to some other character ...

try:

kubectl run --rm -it --tty curl-simple-microservice-server --image=curlimages/curl --restart=Never -- http://simple-microservice-server-service:8080/hello/pippo

it worked for me ....

@tommaso-borgato tommaso-borgato force-pushed the wildfly-mini-serie-client-service branch 4 times, most recently from b97e844 to ffb745e Compare November 28, 2024 09:37
@tommaso-borgato tommaso-borgato force-pushed the wildfly-mini-serie-client-service branch 6 times, most recently from cf300a6 to c14e95d Compare November 29, 2024 15:18
@tommaso-borgato
Copy link
Contributor Author

tommaso-borgato commented Nov 29, 2024

@jamezp Thank you for your review! I hope I have fixed everything you pointed out

@tommaso-borgato
Copy link
Contributor Author

@jamezp Thank you again fro your review, do you think this is ready to be merged now?

@tommaso-borgato
Copy link
Contributor Author

@jamezp Do you think this is ready to be merged now (together with wildfly-extras/guides#4)?

@jamezp
Copy link
Member

jamezp commented Jan 16, 2025

Hello @tommaso-borgato. I apologize, I just haven't had a chance to look at this again. These are fairly large changes and it takes some time to review them and go through the guide. I don't know if I'll have time this week or not, but I can try to make some time next week.

Copy link
Member

@jamezp jamezp left a comment

Choose a reason for hiding this comment

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

I still can't get this to working locally. minikube doesn't seem to work for me with these guides. I'm not sure what the issue is TBH.

Comment on lines 5 to 6
:version-wildfly: 34.0.1.Final
:version-wildfly-galleon-pack: 34.0.1.Final
Copy link
Member

Choose a reason for hiding this comment

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

These should be 35.0.0.Final or we could just leave the version off and use channels which will grab the latest version of WildFly.

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 upgraded the versions and added #724 ... btw "channels" would be yet another concept an inexperienced reader might be confused by ... that is why in #724 I also added the "adding a note about channels" option.

:version-wildfly-maven-plugin: 5.0.0.Final
:version-junit-jupiter-api: 5.11.3
:version-wildfly-cloud-galleon-pack: 7.0.2.Final
:version-wildfly-maven-plugin: 5.0.1.Final
Copy link
Member

Choose a reason for hiding this comment

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

This should be 5.1.1.Final

Comment on lines +49 to +50
* remove folder *src/test*
* remove all test scope dependencies
Copy link
Member

Choose a reason for hiding this comment

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

Why are we doing this? Should the tests just be removed from the example if we remove them 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.

This example is about service ti service invocation and, unless we start both services in the same test, it would fail... perhaps we could leave the tests in the "server" service ...


[source,bash,subs="normal"]
----
kubectl run --rm -it --tty curl-{simple-microservice-server} --image=curlimages/curl --restart=Never --&nbsp;http://{simple-microservice-server}-service:8080/hello/pippo
Copy link
Member

Choose a reason for hiding this comment

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

It's possible I've missed something, but this step fails for me with:

If you don't see a command prompt, try pressing enter.


curl: (28) Failed to connect to simple-microservice-server-service port 8080 after 130287 ms: Could not connect to server
pod "curl-simple-microservice-server" deleted
pod default/curl-simple-microservice-server terminated (Error)

Copy link
Contributor Author

@tommaso-borgato tommaso-borgato Jan 20, 2025

Choose a reason for hiding this comment

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

That's supposed to work if the following have already been deployed:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: simple-microservice-server-deployment
  labels:
    app: simple-microservice-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: simple-microservice-server
  template:
    metadata:
      labels:
        app: simple-microservice-server
    spec:
      containers:
        - name: simple-microservice-server
          image: quay.io/tborgato/simple-microservice-server
          ports:
            - containerPort: 8080
            - containerPort: 9990
          livenessProbe:
            httpGet:
              path: /health/live
              port: 9990
          readinessProbe:
            httpGet:
              path: /health/ready
              port: 9990
          startupProbe:
            httpGet:
              path: /health/started
              port: 9990
apiVersion: v1
kind: Service
metadata:
  name: simple-microservice-server-service
  labels:
    app: simple-microservice-server
spec:
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    app: simple-microservice-server
  type: ClusterIP

Then it is working for me:

]$ kubectl run --rm -it --tty curl-simple-microservice-server --image=curlimages/curl --restart=Never -- http://simple-microservice-server-service:8080/hello/tommy
Hello 'tommy'.pod "curl-simple-microservice-server" deleted

The "Hello 'tommy'" part tells the service is OK

@tommaso-borgato tommaso-borgato force-pushed the wildfly-mini-serie-client-service branch from c14e95d to 42feb0e Compare January 20, 2025 15:30
@tommaso-borgato
Copy link
Contributor Author

@jamezp Thank you for your review! I hope I have answered/fixed everything ...

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.

Guide: WildFly mini series: REST Client
3 participants