Re: Determining parallely deployed versions of a webapp programmatically

2015-12-18 Thread S.Booth
On 16/12/15 14:58, l.pe...@senat.fr wrote:
> I have in some of my apps cron-like tasks, scheduled by libs such as
> quartz.
> 
> As I am also an happy user of the parallel deployment feature of tomcat,
> I was wondering whether, without special privileges such as those of the
> "admin" webapps, I could programatically determine if a webapp is the
> "top" version of a family of webapps.
> 
> So, if webapp versions :
> * 1.2.1
> * 1.2.2
> * 1.2.3
> 
> are deployed, I should be capable to determine that 1.2.3 is the latest
> and only run the scheduled task in this last one.
> 
> Is there any API to achieve that ?
> 
> Thanks in advance,
> 
> Ludovic

I would expect a scheduler like Quartz to run background threads that
might give you class-loader leaks when you un-deploy the application.

I had a similar requirement to yours but compounded by having redundant
tomcat servers. I went the low-tech route of having a heartbeat servlet
pinged by an external cron job that way only a single server (and the
most up-to-date parallel deploy) runs the heartbeat code.

Stephen


==
|epcc| Dr Stephen P Booth Principal Architect   |epcc|
|epcc| s.bo...@ed.ac.uk   Phone 0131 650 5746   |epcc|
==
-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Determining parallely deployed versions of a webapp programmatically

2015-12-17 Thread l.pe...@senat.fr

On 16/12/2015 15:58, l.pe...@senat.fr wrote:

Hi.

I have in some of my apps cron-like tasks, scheduled by libs such as 
quartz.


As I am also an happy user of the parallel deployment feature of 
tomcat, I was wondering whether, without special privileges such as 
those of the "admin" webapps, I could programatically determine if a 
webapp is the "top" version of a family of webapps.


So, if webapp versions :
* 1.2.1
* 1.2.2
* 1.2.3

are deployed, I should be capable to determine that 1.2.3 is the 
latest and only run the scheduled task in this last one.


Is there any API to achieve that ?

I found no API and ended with the following :
1) store the ServletContext on startup, using a ServletContextListener
2) find the tomcat Context from the ServletContext, using MBeans

MBeanServer mBeanServer = 
MBeanServerFactory.findMBeanServer(null).get(0);

ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, 
"managedResource");

Service service = server.findService("Catalina");
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(engine.getDefaultHost());
Container[] children = host.findChildren();
for(int i =  0 ; i < children.length ; i++) {
if(children[i] instanceof Context) {
Context ctx = (Context) children[i];
if(ctx.getServletContext() == sc) {
return ctx;
}
}
}

3)  From the Context, go up to the host and scan contexts, finding those 
whose name starts with the same base name as ours (defined as our name 
stripped from an optionnal ##version ending)

Host host = (Host) context.getParent();

List ret = new ArrayList<>();

Container[] children = host.findChildren();
String shortName = 
StringUtils.substringBefore(context.getName(),"##");

for(int i =  0 ; i < children.length ; i++) {
if(children[i] instanceof Context) {
Context cur = (Context) children[i];
if(StringUtils.startsWith(cur.getName(), shortName)) {
ret.add(cur);
}
}
}
return ret;

StringUtils is here org.apache.commons.lang3.StringUtils.

Note that you should not try to perform 2) in the ServletContextListner 
mentionned in 1), or you deadlock when calling, server.findService.


Any advice from a tomcat expert to enhance this solution welcomed. :-)

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Determining parallely deployed versions of a webapp programmatically

2015-12-16 Thread l.pe...@senat.fr

Hi.

I have in some of my apps cron-like tasks, scheduled by libs such as quartz.

As I am also an happy user of the parallel deployment feature of tomcat, 
I was wondering whether, without special privileges such as those of the 
"admin" webapps, I could programatically determine if a webapp is the 
"top" version of a family of webapps.


So, if webapp versions :
* 1.2.1
* 1.2.2
* 1.2.3

are deployed, I should be capable to determine that 1.2.3 is the latest 
and only run the scheduled task in this last one.


Is there any API to achieve that ?

Thanks in advance,

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org