You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Thiago Veronezi <th...@veronezi.org> on 2017/11/09 02:50:54 UTC

Kill JVM on deployment failure

Guys,

https://github.com/apache/tomee/pull/111

I've created this PR to kill the JVM on any deployment failure. I need to
get an error code from TomEE so docker knows the server died due to some
application error. This way, it will know it needs to start a new container
and try it again until the application is successfully deployed.

Do we have something like this already implemented? If yes, how to use it?

If no, do you guys agree with this approach, or do you think theres a
better way to get a system error?

If you guys agree with the approach, do you have any tip on how to unit
test this? It looks like we can do it with junit (
https://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit),
but I would like to know if you guys can see any clever way to test it
without too much bytecode trickery.

Example of output with this PR...

09-Nov-2017 02:38:39.532 INFO [main]
org.apache.openejb.config.AutoConfig.createContainer Auto-creating a
container for bean servlets.Comp1358857082: Container(type=MANAGED,
id=Default Managed Container)
09-Nov-2017 02:38:39.591 INFO [main]
org.apache.openejb.config.OutputGeneratedDescriptors.writeEjbJar Dumping
Generated ejb-jar.xml to:
/opt/tomee/temp/ejb-jar-4480173124784608261ejbs.xml
09-Nov-2017 02:38:39.842 INFO [main]
org.apache.openejb.config.OutputGeneratedDescriptors.writeOpenejbJar
Dumping Generated openejb-jar.xml to:
/opt/tomee/temp/openejb-jar-1229834934073978679ejbs.xml
09-Nov-2017 02:38:39.888 SEVERE [main]
org.apache.openejb.config.ReportValidationResults.logResults FAIL ...
Hello: Missing
class <home> com.lala.support.demo.ear.ejb2.hello.HelloHomeeeee
09-Nov-2017 02:38:39.889 SEVERE [main]
org.apache.openejb.config.ReportValidationResults.logResults Invalid
EjbModule(name=ejbs, path=/opt/tomee/apps/app/ejbs.jar)
09-Nov-2017 02:38:39.892 INFO [main]
org.apache.openejb.config.ReportValidationResults.deploy Set the
'openejb.validation.output.level' system property to VERBOSE for increased
validation details.
09-Nov-2017 02:38:39.893 WARNING [main]
org.apache.openejb.config.ConfigurationFactory.configureApplication Jar not
loaded. /opt/tomee/apps/app.ear.  Module failed validation.
AppModule(name=app)
09-Nov-2017 02:38:39.893 WARNING [main]
org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration
System property tomee.kill.jvm.on.deployment.failure activated. We will
kill the JVM due to deployment failure.
laplata:demo-tomee-ear tveronezi$

[]s,
Thiago.

Re: Kill JVM on deployment failure

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Thiago

To test it I would create a fake tomee - min libs used by the remoteserver,
in target/mytest/faketomee and create a plain junit test and a nested main
class using remote server that the unit test will launch through a fork.
Then you just need to check the exit code of your fork (Process).

Sirona has that logic for its javaagent if you dont know with this block of
text how to start ;).

On the idea, 3 points:

1. I d replace the flag by an integer which is the exit code. If not set
dont kill otherwise use it as exit code
2. IIRC this is not the only place it can happen so it is a partial impl
probably
3. Why not just implementing in deployer utils (where we have our webapp
deployer) a ExitDeploymentExceptionManager, can be set through system
properties and in your docker you can add this jar easily

Hope it makes sense.


Le 9 nov. 2017 03:51, "Thiago Veronezi" <th...@veronezi.org> a écrit :

> Guys,
>
> https://github.com/apache/tomee/pull/111
>
> I've created this PR to kill the JVM on any deployment failure. I need to
> get an error code from TomEE so docker knows the server died due to some
> application error. This way, it will know it needs to start a new container
> and try it again until the application is successfully deployed.
>
> Do we have something like this already implemented? If yes, how to use it?
>
> If no, do you guys agree with this approach, or do you think theres a
> better way to get a system error?
>
> If you guys agree with the approach, do you have any tip on how to unit
> test this? It looks like we can do it with junit (
> https://stackoverflow.com/questions/309396/java-how-to-
> test-methods-that-call-system-exit),
> but I would like to know if you guys can see any clever way to test it
> without too much bytecode trickery.
>
> Example of output with this PR...
>
> 09-Nov-2017 02:38:39.532 INFO [main]
> org.apache.openejb.config.AutoConfig.createContainer Auto-creating a
> container for bean servlets.Comp1358857082: Container(type=MANAGED,
> id=Default Managed Container)
> 09-Nov-2017 02:38:39.591 INFO [main]
> org.apache.openejb.config.OutputGeneratedDescriptors.writeEjbJar Dumping
> Generated ejb-jar.xml to:
> /opt/tomee/temp/ejb-jar-4480173124784608261ejbs.xml
> 09-Nov-2017 02:38:39.842 INFO [main]
> org.apache.openejb.config.OutputGeneratedDescriptors.writeOpenejbJar
> Dumping Generated openejb-jar.xml to:
> /opt/tomee/temp/openejb-jar-1229834934073978679ejbs.xml
> 09-Nov-2017 02:38:39.888 SEVERE [main]
> org.apache.openejb.config.ReportValidationResults.logResults FAIL ...
> Hello: Missing
> class <home> com.lala.support.demo.ear.ejb2.hello.HelloHomeeeee
> 09-Nov-2017 02:38:39.889 SEVERE [main]
> org.apache.openejb.config.ReportValidationResults.logResults Invalid
> EjbModule(name=ejbs, path=/opt/tomee/apps/app/ejbs.jar)
> 09-Nov-2017 02:38:39.892 INFO [main]
> org.apache.openejb.config.ReportValidationResults.deploy Set the
> 'openejb.validation.output.level' system property to VERBOSE for increased
> validation details.
> 09-Nov-2017 02:38:39.893 WARNING [main]
> org.apache.openejb.config.ConfigurationFactory.configureApplication Jar
> not
> loaded. /opt/tomee/apps/app.ear.  Module failed validation.
> AppModule(name=app)
> 09-Nov-2017 02:38:39.893 WARNING [main]
> org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration
> System property tomee.kill.jvm.on.deployment.failure activated. We will
> kill the JVM due to deployment failure.
> laplata:demo-tomee-ear tveronezi$
>
> []s,
> Thiago.
>

Re: Kill JVM on deployment failure

Posted by Svetlin Zarev <sv...@gmail.com>.
Hi,

For example this would not work if you have unsatisified resource-ref:



09-Nov-2017 09:38:59.118 SEVERE [localhost-startStop-1]
org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal Unable to
deploy collapsed ear in war
StandardEngine[Catalina].StandardHost[localhost].StandardContext[]
 org.apache.openejb.OpenEJBException: Can't find resource for null. (No
provider available for resource-ref 'null' of type
'xxx.yyy.zzz.KeyStoreService' for '.Comp154478778'.)
        at
org.apache.openejb.config.AutoConfig.processResourceRef(AutoConfig.java:1224)
        at org.apache.openejb.config.AutoConfig.deploy(AutoConfig.java:873)
        at org.apache.openejb.config.AutoConfig.deploy(AutoConfig.java:201)
        at
org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:420)
        at
org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:1037)
        at
org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1277)
        at
org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1125)
        at
org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133

Or when a ServletContextListener fails:

09-Nov-2017 09:51:30.180 SEVERE [localhost-startStop-1]
org.apache.catalina.core.StandardContext.startInternal One or more
listeners failed to start. Full details will be found in the appropriate
container log file
09-Nov-2017 09:51:30.180 SEVERE [localhost-startStop-1]
org.apache.catalina.core.StandardContext.startInternal Context [] startup
failed due to previous errors

I didn't test it with ServletContainerInitializer, but I\m pretty sure it
will not work as well.


Have you considered using Tomcat's LifecycleListener to intercept
LifecycleEvent's ?


Best regards,
Svetlin

2017-11-09 4:50 GMT+02:00 Thiago Veronezi <th...@veronezi.org>:

> Guys,
>
> https://github.com/apache/tomee/pull/111
>
> I've created this PR to kill the JVM on any deployment failure. I need to
> get an error code from TomEE so docker knows the server died due to some
> application error. This way, it will know it needs to start a new container
> and try it again until the application is successfully deployed.
>
> Do we have something like this already implemented? If yes, how to use it?
>
> If no, do you guys agree with this approach, or do you think theres a
> better way to get a system error?
>
> If you guys agree with the approach, do you have any tip on how to unit
> test this? It looks like we can do it with junit (
> https://stackoverflow.com/questions/309396/java-how-to-
> test-methods-that-call-system-exit),
> but I would like to know if you guys can see any clever way to test it
> without too much bytecode trickery.
>
> Example of output with this PR...
>
> 09-Nov-2017 02:38:39.532 INFO [main]
> org.apache.openejb.config.AutoConfig.createContainer Auto-creating a
> container for bean servlets.Comp1358857082: Container(type=MANAGED,
> id=Default Managed Container)
> 09-Nov-2017 02:38:39.591 INFO [main]
> org.apache.openejb.config.OutputGeneratedDescriptors.writeEjbJar Dumping
> Generated ejb-jar.xml to:
> /opt/tomee/temp/ejb-jar-4480173124784608261ejbs.xml
> 09-Nov-2017 02:38:39.842 INFO [main]
> org.apache.openejb.config.OutputGeneratedDescriptors.writeOpenejbJar
> Dumping Generated openejb-jar.xml to:
> /opt/tomee/temp/openejb-jar-1229834934073978679ejbs.xml
> 09-Nov-2017 02:38:39.888 SEVERE [main]
> org.apache.openejb.config.ReportValidationResults.logResults FAIL ...
> Hello: Missing
> class <home> com.lala.support.demo.ear.ejb2.hello.HelloHomeeeee
> 09-Nov-2017 02:38:39.889 SEVERE [main]
> org.apache.openejb.config.ReportValidationResults.logResults Invalid
> EjbModule(name=ejbs, path=/opt/tomee/apps/app/ejbs.jar)
> 09-Nov-2017 02:38:39.892 INFO [main]
> org.apache.openejb.config.ReportValidationResults.deploy Set the
> 'openejb.validation.output.level' system property to VERBOSE for increased
> validation details.
> 09-Nov-2017 02:38:39.893 WARNING [main]
> org.apache.openejb.config.ConfigurationFactory.configureApplication Jar
> not
> loaded. /opt/tomee/apps/app.ear.  Module failed validation.
> AppModule(name=app)
> 09-Nov-2017 02:38:39.893 WARNING [main]
> org.apache.openejb.config.ConfigurationFactory.getOpenEjbConfiguration
> System property tomee.kill.jvm.on.deployment.failure activated. We will
> kill the JVM due to deployment failure.
> laplata:demo-tomee-ear tveronezi$
>
> []s,
> Thiago.
>