Re: Using JMX to get ONLY running applications

2016-07-13 Thread Amit Pande
Thanks a lot, Mark for the pointers.

And I apologies if the questions here raise a doubt about lack of homework.

Personally I do try to use Google and/or read and understand documentation
as much as I can. 

Sometimes however I feel (may be wrongly again), documentation is not
enough. E.g. Unless asked here, I would have never known the ³shared²
loader is still supported  (and undocumented) in latest releases. Same is
true with attributes associated with Tomcat Mbeans.


Thanks,
Amit


On 14/07/16 2:18 am, "Mark Thomas"  wrote:

>On 13/07/2016 12:14, Amit Pande wrote:
>> It seems the stateName attribute of MANAGER or WEBMODULE Mbean is NOT
>> getting set correctly if there are any servlet errors.
>> 
>> In particular, when Spring dispatcher servlet is failed to load then the
>> applications state should be STOPPED. However, that does not seem to be
>> the case.
>> 
>> I even checked the SERVLET Mbean as well did not see the expected state.
>> 
>> Is there anything wrong that I am doing ?
>
>Yes.
>
>You are making assumptions based on how you think Tomcat should behave
>rather than reading the documentation that tells you how Tomcat actually
>behaves.
>
>Look in the Context and Host docs for the attribute named:
>failCtxIfServletStartFails
>
>> Is this a BUG ?
>
>No.
>
>> Using Tomcat 8.0.30.
>
>Thanks. Not everyone remembers that.
>
>Mark
>
>
>-
>To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>For additional commands, e-mail: users-h...@tomcat.apache.org
>


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



Re: Using JMX to get ONLY running applications

2016-07-13 Thread Mark Thomas
On 13/07/2016 12:14, Amit Pande wrote:
> It seems the stateName attribute of MANAGER or WEBMODULE Mbean is NOT
> getting set correctly if there are any servlet errors.
> 
> In particular, when Spring dispatcher servlet is failed to load then the
> applications state should be STOPPED. However, that does not seem to be
> the case.
> 
> I even checked the SERVLET Mbean as well did not see the expected state.
> 
> Is there anything wrong that I am doing ?

Yes.

You are making assumptions based on how you think Tomcat should behave
rather than reading the documentation that tells you how Tomcat actually
behaves.

Look in the Context and Host docs for the attribute named:
failCtxIfServletStartFails

> Is this a BUG ?

No.

> Using Tomcat 8.0.30.

Thanks. Not everyone remembers that.

Mark


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



Re: Using JMX to get ONLY running applications

2016-07-13 Thread Amit Pande
Can someone help here ?

It seems the stateName attribute of MANAGER or WEBMODULE Mbean is NOT
getting set correctly if there are any servlet errors.

In particular, when Spring dispatcher servlet is failed to load then the
applications state should be STOPPED. However, that does not seem to be
the case.

I even checked the SERVLET Mbean as well did not see the expected state.

Is there anything wrong that I am doing ? Is this a BUG ? Using Tomcat
8.0.30.

Thanks,
Amit



On 13/07/16 1:05 pm, "Amit Pande" <amit.pa...@veritas.com> wrote:

>I managed to use jCOnsole and find Mbean names and attributes to get the
>stateName (STARTED/STOPPED) to see if a web app is available or NOT
>(j2eeType=WebModule).
>
>However, I see the stateName of a web module as STARTED even if there are
>errors in start-up.
>
> SEVERE [localhost-startStop-3]
>org.apache.catalina.core.StandardContext.loadOnStartup Servlet
>[dispatcher] in web application [/testApp] threw load() exception
>
>I still see state for testApp as "STARTED".
>
>How can I accurately know if the application is started without any
>errors ?
>
>Appreciate your help.
>
>Thanks,
>Amit
>
>From: Amit Pande <amit.pa...@veritas.com<mailto:amit.pa...@veritas.com>>
>Date: Tuesday, 12 July 2016 9:56 pm
>To: "users@tomcat.apache.org<mailto:users@tomcat.apache.org>"
><users@tomcat.apache.org<mailto:users@tomcat.apache.org>>,
>"users-h...@tomcat.apache.org<mailto:users-h...@tomcat.apache.org>"
><users-h...@tomcat.apache.org<mailto:users-h...@tomcat.apache.org>>
>Subject: Using JMX to get ONLY running applications
>
>Hello all,
>
>I see there are JMX APIs to get the web applications currently deployed
>in Tomcat.
>
>However, I see that even if the applications are failed to deploy, they
>still get listed. Is there any way to get ONLY deployed and RUNNING
>applications ?
>
>Below is sample snippet which gives all the currently deployed apps
>..even if there are some apps which had errors and thus failed to deploy:
>
>
>public List collectAllDeployedApps() throws
>MalformedObjectNameException, AttributeNotFoundException,
>InstanceNotFoundException, MBeanException, ReflectionException {
>List webappNames = new ArrayList<>();
>List servers =  MBeanServerFactory.findMBeanServer(null);
>for (MBeanServer server : servers ) {
>Set names = server.queryNames(new
>ObjectName("Catalina:type=Host,*"), null);
>Set hostNames = new HashSet();
>for (ObjectName on : names) {
>hostNames.add(on.getKeyProperty("host"));
>}
>for (String str : hostNames) {
>ObjectName[] webapps = (ObjectName[]) server
>.getAttribute(new ObjectName("Catalina:type=Host,host=" + str),
>"children");
>for (ObjectName ob : webapps) {
>String[] appSpl = ob.getKeyProperty("name").split("//localhost");
>System.out.println(ob.getKeyPropertyList());
>webappNames.add(appSpl[1]);
>}
>}
>}
>return webappNames;
>}
>}
>
>


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



Re: Using JMX to get ONLY running applications

2016-07-13 Thread Amit Pande
I managed to use jCOnsole and find Mbean names and attributes to get the 
stateName (STARTED/STOPPED) to see if a web app is available or NOT 
(j2eeType=WebModule).

However, I see the stateName of a web module as STARTED even if there are 
errors in start-up.

 SEVERE [localhost-startStop-3] 
org.apache.catalina.core.StandardContext.loadOnStartup Servlet [dispatcher] in 
web application [/testApp] threw load() exception

I still see state for testApp as "STARTED".

How can I accurately know if the application is started without any errors ?

Appreciate your help.

Thanks,
Amit

From: Amit Pande <amit.pa...@veritas.com<mailto:amit.pa...@veritas.com>>
Date: Tuesday, 12 July 2016 9:56 pm
To: "users@tomcat.apache.org<mailto:users@tomcat.apache.org>" 
<users@tomcat.apache.org<mailto:users@tomcat.apache.org>>, 
"users-h...@tomcat.apache.org<mailto:users-h...@tomcat.apache.org>" 
<users-h...@tomcat.apache.org<mailto:users-h...@tomcat.apache.org>>
Subject: Using JMX to get ONLY running applications

Hello all,

I see there are JMX APIs to get the web applications currently deployed in 
Tomcat.

However, I see that even if the applications are failed to deploy, they still 
get listed. Is there any way to get ONLY deployed and RUNNING applications ?

Below is sample snippet which gives all the currently deployed apps ..even if 
there are some apps which had errors and thus failed to deploy:


public List collectAllDeployedApps() throws 
MalformedObjectNameException, AttributeNotFoundException, 
InstanceNotFoundException, MBeanException, ReflectionException {
List webappNames = new ArrayList<>();
List servers =  MBeanServerFactory.findMBeanServer(null);
for (MBeanServer server : servers ) {
Set names = server.queryNames(new 
ObjectName("Catalina:type=Host,*"), null);
Set hostNames = new HashSet();
for (ObjectName on : names) {
hostNames.add(on.getKeyProperty("host"));
}
for (String str : hostNames) {
ObjectName[] webapps = (ObjectName[]) server
.getAttribute(new ObjectName("Catalina:type=Host,host=" + str), "children");
for (ObjectName ob : webapps) {
String[] appSpl = ob.getKeyProperty("name").split("//localhost");
System.out.println(ob.getKeyPropertyList());
webappNames.add(appSpl[1]);
}
}
}
return webappNames;
}
}




Using JMX to get ONLY running applications

2016-07-12 Thread Amit Pande
Hello all,

I see there are JMX APIs to get the web applications currently deployed in 
Tomcat.

However, I see that even if the applications are failed to deploy, they still 
get listed. Is there any way to get ONLY deployed and RUNNING applications ?

Below is sample snippet which gives all the currently deployed apps ..even if 
there are some apps which had errors and thus failed to deploy:


public List collectAllDeployedApps() throws 
MalformedObjectNameException, AttributeNotFoundException, 
InstanceNotFoundException, MBeanException, ReflectionException {
List webappNames = new ArrayList<>();
List servers =  MBeanServerFactory.findMBeanServer(null);
for (MBeanServer server : servers ) {
Set names = server.queryNames(new 
ObjectName("Catalina:type=Host,*"), null);
Set hostNames = new HashSet();
for (ObjectName on : names) {
hostNames.add(on.getKeyProperty("host"));
}
for (String str : hostNames) {
ObjectName[] webapps = (ObjectName[]) server
.getAttribute(new ObjectName("Catalina:type=Host,host=" + str), "children");
for (ObjectName ob : webapps) {
String[] appSpl = ob.getKeyProperty("name").split("//localhost");
System.out.println(ob.getKeyPropertyList());
webappNames.add(appSpl[1]);
}
}
}
return webappNames;
}
}