Announcement Announcement Module
Collapse
No announcement yet.
Spring JMX in a distributed Websphere environment Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JMX in a distributed Websphere environment

    Anyone have any expierence with Spring JMX on WebSphere 5.1 and willing share some code snippets? Its seems WebSphere requires you to jump through some hoops in terms of registering an MBean in a manner that will allow it to participate in a distributed environment (for example using the WebSphere specific AdminService or MBeanFactory).

    The vanilla MBeanExporter works, but to use the MBean in a distributed environment, it looks like at minimum the object name needs to contain a type, the cell name, the node name, and process name. Anyone got any ideas?

  • #2
    I can't be sure that MBeanExporter will work in a distributed environment. The JMX spec doesn't really cover distribution currently so most vendors have their own custom solution.

    Rob

    Comment


    • #3
      Ya, I don't expect it to work out of the box, just wondering if anyone has used the MBeanExporter in WebSphere ...

      Comment


      • #4
        AdminService

        The MBean needs to be 'declared' using the AdminService.activateMBean method. Then it becomes 'distributed'.

        Note, JMX with WAS has the following features

        A) If you want to connect to the DMgr from the JMX clients then the DMGR and the node agent on the node with the server hosting the MBean need to be running.

        B) You can avoid this by attaching directly to the SOAP port on the JVM hosting the MBean but if the MBean moves from server to server, this doesn't work.

        We're looking at fixing this in the future by allowing clients to connect to any JVM and find any MBean.

        Billy (IBM)
        http://www.billynewport.com

        Comment


        • #5
          So it needs more than just having the the cell name, node name, and process name in the object name?

          The article here seems to imply that if your object name is crafted correctly it'll work.

          Comment


          • #6
            Help, any response to this ?

            any info from the WAS gurus

            Comment


            • #7
              The following worked

              Get ahold of WebSphere's admin service

              Code:
              <bean id="adminService" class="com.ibm.websphere.management.AdminServiceFactory" factory-method="getAdminService"/>
              Get the bits from the admin service needed for the object name.

              Code:
              <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"/>
              Create the WebSphere object naming strategy

              Code:
              <bean id="websphereNamingStrategy" class="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>
              Export someBean with using the WebSphere object naming strategy.

              Code:
              <bean id="beanExporter" class="org.springframework.jmx.export.MBeanExporter">
                  	<property name="beans">
                    		<map>
                      		<entry key="someBean" value-ref="someBean"/>
                    		</map>
                  	</property>
              	<property name="namingStrategy" ref="websphereNamingStrategy"/>
               </bean>
              WebSphere Object Naming Strategy. Creates an object name with the WebSphere required bits.

              Code:
              public class WebsphereNamingStrategy implements ObjectNamingStrategy 	
              {
                  private String domainName;
                  private String cellName;
                  private String nodeName;
                  private String processName;
                  
                  public ObjectName getObjectName(Object object, String name)
                      throws MalformedObjectNameException
                  {
                      StringBuffer objectName = new StringBuffer();
                      objectName.append(domainName);
                      objectName.append(":cell=");
                      objectName.append(cellName);
                      objectName.append(",name=");
                      objectName.append(name);
                      objectName.append(",type=");
                      objectName.append(ClassUtils.getShortName(object.getClass()));
                      objectName.append(",node=");
                      objectName.append(nodeName);
                      objectName.append(",process=");
                      objectName.append(processName);
                      
              
              	return ObjectNameManager.getInstance(objectName.toString());
                  }
                  
                  
                  public String getCellName()
                  {
                      return cellName;
                  }
                  
                  public void setCellName(String cellName)
                  {
                      this.cellName = cellName;
                  }
                  
                  public String getDomainName()
                  {
                      return domainName;
                  }
                  
                  public void setDomainName(String domainName)
                  {
                      this.domainName = domainName;
                  }
                  public String getNodeName()
                  {
                      return nodeName;
                  }
                  
                  public void setNodeName(String nodeName)
                  {
                      this.nodeName = nodeName;
                  }
                  
                  public String getProcessName()
                  {
                      return processName;
                  }
                  
                  public void setProcessName(String processName)
                  {
                      this.processName = processName;
                  }
              }

              Comment


              • #8
                Can you post this on wiki? thanks.

                Comment


                • #9
                  Where in the wikki should I add it?

                  Comment


                  • #10
                    why not here: http://opensource2.atlassian.com/con...DOC/Spring+JMX ? Add it as a child page

                    Comment


                    • #11
                      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, 07:23 AM.

                      Comment


                      • #12
                        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

                        Comment


                        • #13
                          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

                          Comment


                          • #14
                            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;
                            	    }
                            }

                            Comment


                            • #15
                              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

                              Comment

                              Working...
                              X