Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimize continuous deployment (cancel throu chain-of-responsibility)

Id like to improove continuous delivery. I am using a Tomcat 8 and maven.

I use mvn tomcat:redeploy to deploy the webapp.

In tomcat documentation I found this part:

Deploy A New Application Archive (WAR) Remotely

If installation and startup is successful, you will receive(...)

Otherwise, the response will start with FAIL and include an error message.

As possible causes of FAIL one point is of interrest:

An exception was encountered trying to start the new web application.

So Id like to throw an exception at startup so in the web.xml I write:

<​load-on-startup>1<​/load-on-startup>

to the org.springframework.web.servlet.DispatcherServlet-Servlet. Then I write a Singleton:

@Service
public class AvoidStartupOnMissingDatabase implements SmartInitializingSingleton {

    @Override
    public void afterSingletonsInstantiated() {
        throw new RuntimeException("Do not deploy this app!");
    }
}

This causes this Stacktrace:

java.lang.RuntimeException: Do not deploy this app!
        at xxx.AvoidStartupOnMissingDatabase.afterSingletonsInstantiated(AvoidStartupOnMissingDatabase.java:11)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:630)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:678)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:549)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
        at javax.servlet.GenericServlet.init(GenericServlet.java:158)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4962)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5274)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3823)
        at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1410)
        at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1320)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1648)
        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:497)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1525)
        at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:773)
        at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:443)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:664)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:613)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:486)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

Problem

The application unfortunately deployed!

Screenshot of ci

Question

I fail the init. I said load-on-start. Tomcat said fail if not start. Tomcat said (re)deploy if can start.

So the exception must fail the deployment. Right?

EDIT

I tested tomcat-8.5.30 as well as tomcat-8.5.37, both unfortunately succeed.

like image 684
Grim Avatar asked Feb 03 '19 11:02

Grim


1 Answers

Iv created a bug in Tomcat. The developer guided me to the solution similar to Alexandru Cojocaru.

I moved from a Servlet to a SerlvetContextListener and I successfully receive a "FAIL" for the deployment.

After this invalid deployment the old application is unfortunately not restarted. But the commit to svn is canceled Successfully and is not added to the svn-change-log!

like image 93
Grim Avatar answered Nov 14 '22 10:11

Grim