Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Spring JMX in a distributed Websphere environment

  1. #11

    Default

    i think we can get the cell name , process name , node name and domain name using Websphere API in this way if we deploy the application in cluster environment we will not need to change the Spring configuration files for each Node
    see this link for more info http://publib.boulder.ibm.com/infoce...inService.html
    Code:
     public ObjectName getObjectName(Object object, String name)
            throws MalformedObjectNameException
        {
        	AdminService  adminService = AdminServiceFactory.getAdminService() ;
            StringBuffer objectName = new StringBuffer();
            objectName.append(StringUtils.hasLength(getDomainName())?getDomainName(): adminService.getDomainName() );
            objectName.append(":cell=");
            objectName.append(StringUtils.hasLength(getCellName())?getCellName(): adminService.getCellName());
            objectName.append(",name=");
            objectName.append(name);
            objectName.append(",type=");
            objectName.append(ClassUtils.getShortName(object.getClass()));
            objectName.append(",node=");
            objectName.append(StringUtils.hasLength(nodeName)?nodeName: adminService.getNodeName());
            objectName.append(",process=");
            objectName.append(StringUtils.hasLength(processName)?processName: adminService.getProcessName());
            
    
    	return ObjectNameManager.getInstance(objectName.toString());
        }
    Last edited by usama_ra1; Jul 24th, 2007 at 06:23 AM.

  2. #12
    Join Date
    Aug 2006
    Posts
    14

    Default Websphere console steps for Mbean mgmt

    Hi,

    How do i bring up the Mbeans in Websphere console and manage them? - It'll be great if the steps for doing that can be posted as well. As i understand, the code snippet creates and registers Mbeans. I'm totally new to JMX, and am using RAD 7 (WAS 6.1)

    Thanks,
    Joseph

  3. #13
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    121

    Default

    Quote Originally Posted by jaalex View Post
    How do i bring up the Mbeans in Websphere console and manage them? - It'll be great if the steps for doing that can be posted as well. As i understand, the code snippet creates and registers Mbeans. I'm totally new to JMX, and am using RAD 7 (WAS 6.1)
    Unfortunately, WebSphere doesn't offer that functionality. To access your MBeans, use the wsadmin console that ships with WebSphere. Search the InfoCenter for more information on how to do that.

    Joris

  4. #14
    Join Date
    Sep 2007
    Posts
    5

    Default

    Quote Originally Posted by jaalex View Post
    Hi,

    How do i bring up the Mbeans in Websphere console and manage them? - It'll be great if the steps for doing that can be posted as well. As i understand, the code snippet creates and registers Mbeans. I'm totally new to JMX, and am using RAD 7 (WAS 6.1)

    Thanks,
    Joseph

    I use mx4j as a console in WebSphere 6.0. Took a tip till I found a class called org.springframework.jmx.support.WebSphereMBeanServ erFactoryBean. Apparently this bean is not needed if you work with WebSphere 6.1.

    My configuration is:

    Code:
    	<bean id="adminService" class="com.ibm.websphere.management.AdminServiceFactory" factory-method="getAdminService"/>
    
    	<bean id="adminService.defaultDomain" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
    	<bean id="adminService.cellName" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
    	<bean id="adminService.nodeName" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
    	<bean id="adminService.processName" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
    
    	<bean id="websphereNamingStrategy" class="example.WebsphereNamingStrategy">
        	<property name="domainName" ref="adminService.defaultDomain"/>
    		<property name="cellName" ref="adminService.cellName"/>
    		<property name="nodeName" ref="adminService.nodeName"/>
    		<property name="processName" ref="adminService.processName"/>
    	</bean>
    
    	<bean id="mbeanServer" class="org.springframework.jmx.support.WebSphereMBeanServerFactoryBean" />
    	<bean id="processor" class="mx4j.tools.adaptor.http.XSLTProcessor" />
    
    	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
    		<property name="server" ref="mbeanServer" />
    		<property name="namingStrategy" ref="websphereNamingStrategy"/>
    		<property name="beans">
    			<map>
    				<entry key="MyBean" value-ref="MyBean"/>
       				<entry key="HttpAdaptor">
    				    <bean class="mx4j.tools.adaptor.http.HttpAdaptor">
    				      <property name="port" value="8000"/>
    				      <property name="host" value="0.0.0.0"/>
    				      <property name="processor" ref="processor"/>
    				    </bean>
    			    </entry>
    			</map>
    		</property>
    		<property name="assembler">
    			<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
    				<property name="interfaceMappings">
    					<map>
    						<entry key="MyBean" value="example.MyBeanInterface"/>
    					</map>
    				</property>
    			</bean>
    		</property>
    	  <property name="listeners">
    		   <list>
    			    <!-- let the HttpAdapter be started after it is registered in the MBeanServer -->
    			    <bean class="example.HttpAdapterManager">
    			    	<property name="mbeanServer" ref="mbeanServer" />
    			    </bean>
    		   </list>
    	  </property>
    	  <property name="exposeManagedResourceClassLoader" value="true" />
    	</bean>
    I'm not sure whether the property exposeManagedResourceClassLoader is needed in the configuration.

    The code for the AdapterManager (has to be rewritten to use the namingstrategy for WebSphere but this is the idea). The code starts the HttpAdaptor:

    Code:
    package example;
    
    import javax.management.MBeanServer;
    import javax.management.ObjectName;
    
    import org.springframework.jmx.export.MBeanExporterListener;
    
    public class HttpAdapterManager implements MBeanExporterListener  {
    
    	    private MBeanServer mbeanServer;
    	    private String adaptorName = "Server:name=HttpAdaptor";
    
    	    public void mbeanRegistered(ObjectName objectName) {
    	        if (adaptorName.equals(objectName.getCanonicalName())) {
    	            try {
    	                mbeanServer.invoke(objectName, "start", null, null);
    	            } catch (Exception e) {
    	                System.err.println("Can't start HttpAdaptor: " + e);
    	            }
    	        }
    	    }
    
    	    public void mbeanUnregistered(ObjectName objectName) {
    	        if (adaptorName.equals(objectName.getCanonicalName())) {
    	            try {
    	                mbeanServer.invoke(objectName, "stop", null, null);
    	            } catch (Exception e) {
    	                System.err.println("Can't stop HttpAdaptor: " + e);
    	            }
    	        }
    	    }
    
    	    public void setMbeanServer(MBeanServer mbeanServer) {
    	        this.mbeanServer = mbeanServer;
    	    }
    
    	    public void setAdaptorName(String adaptorName) {
    	        this.adaptorName = adaptorName;
    	    }
    }

  5. #15
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    121

    Default

    Hey, that code looks strangely familiar
    Be sure to use the same ObjectName for the HttpAdapter in your MBeanExporter and in your HttpAdapterManager, as Lukas already hinted: when using this WebSphereNamingStrategy, using equals() to match the names therefore wouldn't be such a good idea.
    Also, I like usama_ra1's code solution a lot better than the one that does all the 'programming' in Spring XML configuration, so you might want to go with that one. Just remember that you ONLY need this if your application is running inside a clustered configuration with a running deployment manager AND you want to be able to connect to MBean running in other nodes from your application. Otherwise, any regular NamingStrategy will do.

    BTW, the reason that you can't simply say init-method="start" on the HttpAdaptor bean is that it can't be started untill it's actually registered inside the MBean Server; using an MBeanExporterListener can take care of that.
    By default, MX4J's HttpAdaptor will only be accessible from the same server that it's running on: setting the host property to 0.0.0.0 makes it globally accessible. You might not want to do that on your production servers Check the MX4J docs for more info on securing the adaptor: http://mx4j.sourceforge.net/docs/ch05.html

  6. #16
    Join Date
    Sep 2007
    Posts
    5

    Default

    Quote Originally Posted by Joris Kuipers View Post
    Hey, that code looks strangely familiar
    Be sure to use the same ObjectName for the HttpAdapter in your MBeanExporter and in your HttpAdapterManager, as Lukas already hinted: when using this WebSphereNamingStrategy, using equals() to match the names therefore wouldn't be such a good idea.
    Also, I like usama_ra1's code solution a lot better than the one that does all the 'programming' in Spring XML configuration, so you might want to go with that one. Just remember that you ONLY need this if your application is running inside a clustered configuration with a running deployment manager AND you want to be able to connect to MBean running in other nodes from your application. Otherwise, any regular NamingStrategy will do.
    I agree the other solution is cleaner. I use the context because I develop on a Tomcat server and deploy it on a WebSphere server. This way I can have the same java code on both servers, only the applicationContext.xml differs.

    If you have suggestions on other ways how to solve this please let me know.
    Last edited by lgommers; Oct 4th, 2007 at 04:39 AM.

  7. #17
    Join Date
    Oct 2007
    Posts
    5

    Default InstanceAlreadyExistsException

    I have followed this thread to the letter on WAS 6.0/Spring 1.2 and am still getting the exception I was hoping it was going to rectify (albeit the naming solution itself appears to be doing what it should in terms of generating something meaningful)

    javax.management.InstanceAlreadyExistsException: WebSphere:cell=E8264ZD50145171Node01Cell,name=pcis ScheduleTestXYZ,type=CronTriggerBean,node=E8264ZD5 0145171Node01,process=server1

    Is there any way that I can register my bean as an MBean ? I am running out of ideas....I can't even get it to register once let alone anything to do with a redeploy.

    Thx

  8. #18
    Join Date
    Feb 2008
    Posts
    15

    Default using WS 6.x

    Can anyone tell me whether the object name as shown by dritchey (in the post from 02-07-2006, 06:27 PM) needs to set in WebSphere 6.1 -or- was the object name requirements only for WebSphere 5.x

    Also, if I'm running not running my app. in a clustered env. then do I need to worry about the object name restriction.

    To add to this, I have been able to successfully deploy my MBean app. on WS and was able to view and update my MBeans using the JConsole. The issue I'm running into is that when I stop and restart the server, the server fails to restart. There is nothing useful in the JVM log files. I"m wondering if the server fails to unregister my beans (because I have not provided the fully qualified WS name) and when the server tries to restart, it cannot deploy my MBean and the server fails to start.

    thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •