Generator-jhipster: jhipster-registry Docker doesn't work if the app is started without Docker

Created on 7 Sep 2016  ·  12Comments  ·  Source: jhipster/generator-jhipster

Overview of the issue

It only concerns gateway/microservice application.

When starting the docker jhipster registry with
docker-compose -f src/main/docker/jhipster-registry.yml,
then, start the project (gateway or microservice) with ./mvnw, it's broken.

See the log:

2016-09-07 08:16:16.450 ERROR 8220 --- [       Thread-8] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: registry
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
    at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
    at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
    at com.sun.jersey.api.client.Client.handle(Client.java:652)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.delete(WebResource.java:591)
    at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.cancel(AbstractJerseyEurekaHttpClient.java:76)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
    at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118)
    at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:119)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
    at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
    at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71)
    at com.netflix.discovery.DiscoveryClient.unregister(DiscoveryClient.java:902)
    at com.netflix.discovery.DiscoveryClient.shutdown(DiscoveryClient.java:880)
    at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.cloud.context.config.StandardBeanLifecycleDecorator$2.invoke(StandardBeanLifecycleDecorator.java:85)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
    at org.springframework.cloud.netflix.eureka.CloudEurekaClient$$EnhancerBySpringCGLIB$$e151ea6.shutdown(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy143.shutdown(Unknown Source)
    at org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration.onApplicationEvent(EurekaDiscoveryClientConfiguration.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:226)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:143)
    at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:105)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:989)
    at org.springframework.context.support.AbstractApplicationContext$2.run(AbstractApplicationContext.java:923)
Caused by: java.net.UnknownHostException: registry
    at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:262)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:161)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173)
Reproduce the error
  • generate a gateway or microservice application
  • start the docker jhipster-registry with: docker-compose -f src/main/docker/jhipster-registry.yml
  • start your project with: ./mvnw or ./gradlew

It's because the jhipster-registry.yml has a volume, which provides this config
src/main/docker/central-server-config/application.yml and this value:

eureka:
    client:
        serviceUrl:
            defaultZone: http://admin:admin@registry:8761/eureka/

This value is only needed when we start the full stack with the app.yml file

Suggest a Fix

Distinct 2 files:

  • src/main/docker/central-server-config/dev/application.yml -> without the value eureka.client.serviceUrl.defaultZone
  • src/main/docker/central-server-config/app/application.yml -> with the value eureka.client.serviceUrl.defaultZone
  • different volumes for jhipster-registy.yml and app.yml

1) docker jhipster-registry + start project will work

  • docker-compose -f src/main/docker/jhipster-registry.yml up -d
  • ./mvnw

2) start everything with docker will still work

  • ./mvnw -Pprod package docker:build
  • docker-compose -f src/main/docker/app.yml up

:warning: My PR is almost ready, if you are OK with this, I will submit.
@PierreBesson : if you can have a fast look plz, as I know you worked a lot on spring cloud config

JHipster Version(s)
[email protected] /home/pgrimaud/projects/test/05-gateway
└── [email protected]  -> /home/pgrimaud/projects/jhipster/generator-jhipster

JHipster configuration, a .yo-rc.json file generated in the root folder
{
  "generator-jhipster": {
    "jhipsterVersion": "3.6.1",
    "baseName": "jhgate",
    "packageName": "io.github.pascalgrimaud",
    "packageFolder": "io/github/pascalgrimaud",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "hazelcast",
    "clusteredHttpSession": "no",
    "websocket": "no",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": "no",
    "buildTool": "maven",
    "jwtSecretKey": "f7191675a8ae5f77641f6596bd85cac554d8f225",
    "useSass": false,
    "applicationType": "gateway",
    "testFrameworks": [
      "gatling"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en"
    ],
    "enableSocialSignIn": false
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory

ls: no such file or directory: .jhipster/*.json

Browsers and Operating System

openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

git version 2.7.4

node: v4.5.0

npm: 3.10.6

bower: 1.7.9

gulp:
[08:32:45] CLI version 1.2.2
[08:32:45] Local version 3.9.1

yeoman: 1.8.4

Docker version 1.12.1, build 23cf638

docker-compose version 1.8.0, build f3628c7

Most helpful comment

I know this is somehow dirty, but it works for me....I put

127.0.0.1 registry

to my hosts file...this doesn't force me to change the app config..

All 12 comments

Yes, I either use it:

  • With Docker Compose, with some dockerized apps and our docker-compose sub-generator
  • Directly with Docker, with some non-dockerized apps

So here you have a different usage, which is indeed logical - it's such I hadn't thought of it.

Then we have most Docker files in src/main/docker and it's already a bit annoying to cd to that directory all the time - so if you put more directories I don't find it very user-friendly.

A simplier solution would be to move these 2 lines https://github.com/jhipster/generator-jhipster/blob/master/generators/server/templates/src/main/docker/_jhipster-registry.yml#L6-L7 to the app.yml file

I think its better, no adding more file to confuse user

About my use case, starting registry with docker and start the app with mvnw or java -jar, it's what our Travis already do.

So the app never start for gateway and microservice. But as we didn't test if the app is started or not, we dont notice about it

Yes your new solution is much simpler

Sorry it's m'y fault it's broken ! Now I realize I broke it when fixing the dev profile on the registry docker image. Actually before you could not edit the config when running the registry from src/main/docker/JHipster-registry.yml, it was taking its config from a default git repo.

@jdubois This use case is very justified it's similar to running the mysql.yml in dev...

I think what we must do is set the default zone to : http://admin:admin@localhost:8761/eureka/ in SRC/main/docker/central-config/application.yml. This way it would be correctly configured.

And you can do a different directory for app.yml and JHipster registry.yml.

@pascal if you don't have the time to do it tonight I will do it early tomorrow, no problem.

@PierreBesson : if you change the default zone to http://admin:admin@localhost:8761/eureka/ in src/main/docker/central-config/application.yml, the app.yml won't work, as everything will run in Docker containers, so localhost would be incorrect

@PierreBesson : what do you think about the 2nd solution I suggested ?
Moving these lines from jhipster-registry.yml to app.yml :

        volumes:
            - ./central-server-config:/central-config

The only "cons" is Config Server: Not found or not setup for this application when we start the app in dev... But we can document it (or maybe it's already done)

@pascalgrimaud I'm working on it. I think I found a solution...

Hi,

I'm running the gateway without docker container. But I'm getting a issue that is related with this bug.

The version that I'm working is 3.8.0.

Caused by: java.net.UnknownHostException: registry

Do you all think it's a config problem that i have to do in my project?

@vinicius91carvalho check that localhost-config/application.yml has this:

eureka:
    client:
        serviceUrl:
              defaultZone: http://admin:admin@localhost:8761/eureka/

This is essential to configure your app to use the "localhost" registry host instead of "registry".

I know this is somehow dirty, but it works for me....I put

127.0.0.1 registry

to my hosts file...this doesn't force me to change the app config..

I know this is somehow dirty, but it works for me....I put

127.0.0.1 registry

to my hosts file...this doesn't force me to change the app config..

With the newer version: the fallback is 127.0.0.1 jhipster-registry

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pascalgrimaud picture pascalgrimaud  ·  3Comments

tomj0101 picture tomj0101  ·  3Comments

dronavallisaikrishna picture dronavallisaikrishna  ·  3Comments

SudharakaP picture SudharakaP  ·  3Comments

pascalgrimaud picture pascalgrimaud  ·  4Comments