WebSphere Application Server & Liberty

WebSphere Application Server & Liberty

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Mon October 19, 2020 09:58 AM

    is it possible to connect a remote WebSphere traditional (8.5.5.14) cell using an admin client web app deployed in Liberty?

    I have a CLI that uses com.ib.webspehre.management.AdminClient to connect to remote WAS traditional cells to get config information via JMX over SOAP and I would like to be able to run it from a web app in Liberty (full ND 20.0.0.9).

    The CLI uses the admin client, security, and crypto jars to connect securely via SOAP using AdminClient but these jars collide with classes that appear to be in Liberty runtime (for example, WsLogger is different in Liberty and is loaded first), so it doesn't appear to be possible to use the existing AdminClient.

    Is there a new API that replaces AdminClient that I can use to connect to our WAS traditional cells to query config information from a web in Liberty?

    ------------------------------
    Neil Graham
    Consultant
    CBSA
    ------------------------------


  • 2.  RE: Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Tue October 20, 2020 11:52 AM
    > Is there a new API that replaces AdminClient that I can use to connect to our WAS traditional cells to query config information from a web in Liberty?

    No, if you want to access traditional WebSphere from a client application in WebSphere Liberty, you're best (only?) option is to write a JMX *thin* client to access the Mbeans in traditional WebSphere 
    As noted in  https://www.ibm.com/support/knowledgecenter/SSAW57_9.0.5/com.ibm.websphere.nd.multiplatform.doc/ae/tcli_chooseclient.html  which states (in part)
    " However, the thin clients running on J2SE do not support a Java EE container that provides easy access to system services for object resolution, security, Reliability Availability and Servicability (RAS), and other services."

    Another alternative might be to package the tWAS logger implementation jar with your existing application and change the classloader https://www.ibm.com/support/knowledgecenter/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/twlp_classloader_alt_api.html

    ------------------------------
    Tom Alcott
    Senior Technical Staff Member
    IBM
    ------------------------------



  • 3.  RE: Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Tue October 20, 2020 03:57 PM
    Thanks Tom,

    I will give it a shot using the link you provided.  For what it is worth, I did try to use the different jars and changing the classloader order, but that just caused a mess of missing classes in server.

    ------------------------------
    Neil Graham
    Consultant
    CBSA
    ------------------------------



  • 4.  RE: Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Wed October 21, 2020 10:06 AM
    I had a look and perhaps my description of what I'm trying to accomplish was too vague.  In WebSphere traditional, I can use IBMs proprietary AdminClient API to access other WAS cells to query for configuration information via JMX.  I can do this from both a webapp deployed to WAS traditional since it includes all the APIs I need to call and from a CLI thin client.   I'm just wondering if I can move the webapp to Liberty instead of WAS traditional. 

    The proprietary AdminClient API doesn't appear to be in Liberty (and can't be packaged as separate jars due to conflicts), but is there any API that allows me to access remote WAS traditional JMX beans that is provided in Liberty?  Does Liberty not support running a JMX client in a webapp or EJB module?





    ------------------------------
    Neil Graham
    Consultant
    CBSA
    ------------------------------



  • 5.  RE: Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Wed October 21, 2020 01:04 PM
    Neil

    > but is there any API that allows me to access remote WAS traditional JMX beans that is provided in Liberty? Does Liberty not support running a JMX client

    Got it, I pointed you to the thin client in case that had fewer tWAS dependencies which would result in implementation conflicts,  while minimizing the application code changes

    As far as an API, that would be plain JMX (or JSR-160), as opposed to the tWAS JMX extensions which are employed with the tWAS administrative client API
    In any event, there are several articles in the knowledge center that discuss a JMX-160 client which will run in any Java SE environment (JMX has been part of Java SE since Java SE 5) 
    Take a look at the following 
    https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/tjmx_customjava_jsr160.html
    https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/tjmx_develop_jsr160.html
    https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cjmx_mult_appsrvr.html

    which should get you started

    I'll add that because of the different architecture and management model for Liberty there's no administrative API, as there is with tWAS, ; Liberty completely documents the configuration model, which can be managed in one or many configuration files using any mechanism you choose from a plain text editor to shell scripting tools (e.g. Sed,  Awk, etc) to Java scripting (e.g Jython, Ruby, etc), while the tWAS configuration file structure is undocumented (for the most part), and the  tWAS supplied administrative  interfaces. the adminconsole, wsadmin and adminclient API are the only supported means for managing the configuration (these interfaces insure consistency between the the multiple files that comprise the tWAS configuration)


    ------------------------------
    Tom Alcott
    Senior Technical Staff Member
    IBM
    ------------------------------



  • 6.  RE: Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Wed October 21, 2020 03:06 PM
    Thanks very much Tom.  Your help is greatly appreciated.

    I have been looking at those resources but am struggling a bit with the correct URL and initial context factory to use when connecting to traditional WAS. I will keep plugging away though.

    After working with the configuration of traditional WAS for quite a while now, I find the simplicity and ease of the Liberty configuration very refreshing. Unfortunately, all of our existing infrastructure is still traditional WAS, so I need to connect to it. 

    in any event, I can run the webapp in traditional WAS if I can't get it working in Liberty, I just would have preferred Liberty.

    Thanks again
    Neil

    ------------------------------
    Neil Graham
    Consultant
    CBSA
    ------------------------------



  • 7.  RE: Use JMX to connect to WebSphere traditional cells from WebSphere Liberty web app?

    Posted Wed October 21, 2020 04:15 PM
    Edited by Tom Alcott Wed October 21, 2020 04:15 PM
    Neil

    FWIW, here's some (ancient) JSR 160 JMX code, circa 2008, running in webapp (in tWAS) that accesses an MBean, which you might find helpful 
    The webapp used the  inputs
    a) host (the FQHN)
    b) port (9809 the Dmgr bootstrap port)
    c) the name of an Mbean
    d) admin user name
    e) admin user pwd

      and returned information about the Mbean, instead of a specific Mbean one could query all

    I haven't touched this this decade, but I'd expect it to still work


    public String countViaJSR160(String host, String port, String bean, String username, String password) {
    System.out.println("Connecting via JSR160 APIs");
    String jndiPath="/jndi/JMXConnector";

    String serviceURL = "service:jmx:iiop://"+host+":" + port + jndiPath;
    System.out.println("ServiceURL = "+ serviceURL);
    String out = "JSR160 ";
    try {
    JMXServiceURL url = new JMXServiceURL(serviceURL);

    Hashtable h = new Hashtable();

    //Specify the username and password for the server if security is enabled on server.
    //If the username is null, then we don't add the credentials, and use the credentials of the current thread.

    if (username != null) {
    System.out.println("Adding credentials "+ username + " " + password);
    String[] credentials = new String[] {username, password};
    h.put("jmx.remote.credentials", credentials);
    }

    //Establish the JMX connection.

    JMXConnector jmxc = JMXConnectorFactory.connect(url, h);

    //Get the MBean server connection instance.

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    System.out.println("Connected to " + serviceURL);

    int count = mbsc.getMBeanCount();
    out += " getMBeanCount() = " + count;
    System.out.println(out);

    String query = "*:*,name="+bean;
    final ObjectName name = new ObjectName(query);

    Set<ObjectName> queryNames = mbsc.queryNames(name, null);

    System.out.println("Query returned " + queryNames.size());

    for (final ObjectName objectName : queryNames) {
    System.out.println(count++ + ":" + objectName.getCanonicalName());
    mbsc.invoke(objectName, "resetDefinitions", null, null);
    out += "; invoked resetDefinitions.";
    System.out.println(out);
    }

    } catch (MalformedURLException e) {
    System.out.println("MalformedURLException " + e);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    } catch (MalformedObjectNameException e) {
    e.printStackTrace();
    } catch (NullPointerException e) {
    e.printStackTrace();
    } catch (InstanceNotFoundException e) {
    e.printStackTrace();
    } catch (MBeanException e) {
    e.printStackTrace();
    } catch (ReflectionException e) {
    e.printStackTrace();
    }
    return out;

    }

    ------------------------------
    Tom Alcott
    Senior Technical Staff Member
    IBM
    ------------------------------