jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.58k stars 4.02k forks source link

Creating a microservices stack with `reactive-ms.jdl` and the `main` branch doesn't work #21226

Closed mraible closed 1 year ago

mraible commented 1 year ago
Overview of the issue

I'm trying to re-create a demo I did a couple of years ago to work with JHipster 8 (aka, the main branch).

jhipster jdl reactive-ms.jdl

If I start all the Docker instances necessary for each app, then run them with Gradle, they're unable to connect to the JHipster Registry.

2023-02-23T23:24:29.403-07:00  WARN 72389 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: I/O error on PUT request for "http://admin:admin@jhipster-registry:8761/eureka/apps/GATEWAY/gateway:6ccc6ad2a5b3d06c3042c73107c92a9c": jhipster-registry
2023-02-23T23:24:29.403-07:00 ERROR 72389 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_GATEWAY/gateway:6ccc6ad2a5b3d06c3042c73107c92a9c - was unable to send heartbeat!

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
        at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$3.execute(EurekaHttpClientDecorator.java:92)
        at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89)
        at com.netflix.discovery.DiscoveryClient.renew(DiscoveryClient.java:837)
        at com.netflix.discovery.DiscoveryClient$HeartbeatThread.run(DiscoveryClient.java:1401)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Motivation for or Use Case

It should be possible to generate a microservices architecture with a JDL that worked with JHipster 7.

Reproduce the error

Install JHipster 8 from its main branch:

git clone https://github.com/jhipster/generator-jhipster.git
cd generator-jhipster
npm install
npm link

Create a directory called reactive-stack and initialize git.

take reactive-stack # mkdir reactive-stack && cd reactive-stack
git init # initialize git, so apps aren't created with their own .git

Import the reactive-ms architecture definition from the jdl-samples repository and generate gateway, blog, and store apps.

jhipster jdl reactive-ms.jdl

Run the following commands to start Keycloak, PostgreSQL, and the JHipster Registry.

cd gateway
docker compose -f src/main/docker/keycloak.yml up -d
docker compose -f src/main/docker/jhipster-registry.yml up -d
./gradlew

Open a new terminal window, start the blog app's Neo4j database, and then the app itself.

cd ../blog
docker compose -f src/main/docker/neo4j.yml up -d
./gradlew

Open another terminal window, start the store app's MongoDB database, and the microservice.

cd ../store
docker compose -f src/main/docker/mongodb.yml up -d
./gradlew

Open http://localhost:8080 in your favorite browser. You will be able to log in with admin/admin as credentials, but you won't be able to view any entities.

atomfrede commented 1 year ago

Can this be related to consul as default service discovery mechanism?

mraible commented 1 year ago

@atomfrede Possibly. If I create a microservices architecture with jhipster jdl reactive-mf.jdl, it works. This JDL uses Consul instead of JHipster Registry.

mraible commented 1 year ago

Do you know why this might be happening, @deepu105? Are you able to reproduce it?

mraible commented 1 year ago

Today, I discovered that jhipster jdl reactive-ms.jdl doesn't create any files in the docker-compose directory. Here's the relevant section from the JDL:

deployment {
  deploymentType docker-compose
  appsFolders [gateway, blog, store]
  dockerRepositoryName "mraible"
}
mraible commented 1 year ago

Added a bug bounty to try and get this fixed. I was hoping to use jhipster jdl reactive-ms.jdl in my demo next Tuesday.

mshima commented 1 year ago

The deployment is missing the serviceDiscovery since eureka is not default anymore. But from your reproduction, doesn’t sounds related.

mshima commented 1 year ago

CI is passing with eureka. I will try to reproduce.

mshima commented 1 year ago

@mraible

cd gateway
docker compose -f src/main/docker/keycloak.yml up -d
docker compose -f src/main/docker/jhipster-registry.yml up -d
./gradlew

fails due to a race condition. jhipster-registry fails to start due to keycloak not started.

cd gateway
docker compose -f src/main/docker/services.yml up -d
./gradlew

I've added the services.yml recently. Works.

mraible commented 1 year ago

@mshima I was using npm run ci:e2e:prepare, which does use services.yml. I tried manually using:

docker compose -f src/main/docker/services.yml up -d

The JHipster Registry starts up just fine and I can log in to it via Keycloak at http://localhost:8761.

If I start the gateway using ./gradlew, it fails to register itself.

----------------------------------------------------------
2023-02-27T15:22:24.501-07:00  INFO 13013 --- [  restartedMain] com.okta.developer.gateway.GatewayApp    :
----------------------------------------------------------
        Config Server:  Connected to the JHipster Registry running in Docker
----------------------------------------------------------
2023-02-27T15:22:29.415-07:00  INFO 13013 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  
: Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://admin:admin@jhipster-registry:8761/eureka/}, exception=I/O error on PUT request for "http://admin:admin@jhipster-registry:8761/eureka/apps/GATEWAY/gateway:efbea8dda11e5eca83d671613c2cc33e"
: jhipster-registry stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on PUT request for "http://admin:admin@jhipster-registry:8761/eureka/apps/GATEWAY/gateway:efbea8dda11e5eca83d671613c2cc33e":

I'm using openjdk 17.0.6 2023-01-17 on an M1.

mshima commented 1 year ago

@mraible so you have jhipster-registry host pointing to localhost?

mraible commented 1 year ago

@mshima I'm just trying to make this tutorial work with JHipster 8. When I compared the generated jhipster-registry.yml from the tutorial's example and the one generated by JHipster 8, I found the fix in https://github.com/jhipster/generator-jhipster/pull/21246 to be the only difference. Changing it from docker to localhost solves this issue.

mraible commented 1 year ago

I'm seeing strange behavior when running the following commands:

take reactive-stack
jhipster jdl reactive-ms.jdl

It generates everything pretty quickly, likely because JHipster no longer runs npm install by default.

...
   create gateway/src/main/docker/services.yml
   create gateway/src/test/javascript/cypress/e2e/entity/blog.cy.ts
   create gateway/src/test/javascript/cypress/e2e/entity/post.cy.ts
   create gateway/src/test/javascript/cypress/e2e/entity/tag.cy.ts
   create gateway/src/test/javascript/cypress/e2e/entity/product.cy.ts
Execution time: 7 s.

However, there are no files generated in the docker-compose directory. However, if I run jhipster jdl reactive-ms.jdl again, it works the 2nd time.

...
identical store/src/test/java/com/okta/developer/store/domain/ProductTest.java
identical store/src/main/docker/grafana/provisioning/dashboards/JVM.json
identical store/src/main/docker/grafana/provisioning/datasources/datasource.yml

No change to package.json was detected. No package manager install will be executed.
✔ Git repository initialized.
✔ Application successfully committed to Git from /Users/mraible/Downloads/reactive-stack/store.
✔ Spring Boot application generated successfully.
  Run your Spring Boot application:
  ./gradlew
INFO! Generator app succeed
INFO! Generating 1 deployment.
INFO! Docker is installed

Found .yo-rc.json config file...
🐳  Welcome to the JHipster Docker Compose Sub-Generator 🐳
Files will be generated in folder: /Users/mraible/Downloads/reactive-stack/docker-compose

Checking Docker images in applications directories...
    force docker-compose/.yo-rc.json
   create docker-compose/docker-compose.yml
   create docker-compose/README-DOCKER-COMPOSE.md
   create docker-compose/central-server-config/application.yml
   create docker-compose/realm-config/jhipster-realm.json

No change to package.json was detected. No package manager install will be executed.
WARNING! Docker Compose configuration generated, but no Jib cache found
WARNING! If you forgot to generate the Docker image for this application, please run:
To generate the missing Docker image(s), please run:
  ./gradlew bootJar -Pprod jibDockerBuild in /Users/mraible/Downloads/reactive-stack/gateway
  ./gradlew bootJar -Pprod jibDockerBuild in /Users/mraible/Downloads/reactive-stack/blog
  ./gradlew bootJar -Pprod jibDockerBuild in /Users/mraible/Downloads/reactive-stack/store

INFO! You can launch all your infrastructure by running : docker compose up -d
INFO! Generator docker-compose succeed

Congratulations, JHipster execution is complete!
If you find JHipster useful consider sponsoring the project https://www.jhipster.tech/sponsors/

Sponsored with ❤️  by @oktadev.
Execution time: 13 s.

FWIW, I see the same behavior when running jhipster jdl reactive-mf.jdl.