adequate
adequate
adequate
adequate
 

JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   Forums 
May 29, 2017, 02:06:56 AM *
Welcome,
Please login or register.

Login with username, password and session length
Advanced search  
News: New users, please read this message. Thank you!
  Home Help Search Login Register  
Pages: [1]   Go Down

Author Topic: How do I make use of transient JPPFSystemInformation ?  (Read 37 times)

safeer

  • JPPF Padawan
  • *
  • Posts: 2
How do I make use of transient JPPFSystemInformation ?
« on: April 07, 2017, 09:06:12 AM »

I am trying to iterate through nodes and try to print node details like IP Address, Host name, OS name, system architecture, etc
Came across  JPPFSystemInformation, an instance of this object is returned by comp.getManagementInfo().getSystemInfo()
Unfortunately this object is null and I am not able to access OS name or any system properties.
How can I make use of getManagementInfo().getSystemInfo() ? OR How do I get node's OS Name and system architecture.

// iterate over the discovered drivers
   for (TopologyDriver driver: manager.getDrivers()) {
       // ... do something with the driver ...
       // iterate of the nodes and peers for this driver
       for (AbstractTopologyComponent comp: driver.getChildren()) {
           if (comp.isNode()) {
         JPPFSystemInformation infoObj = comp.getManagementInfo().getSystemInfo();
         if(infoObj == null) System.out.println("NULL SYSINFO OBJECT");
                       System.out.println("Node: " + comp.getDisplayName() + ", "
            + comp.getManagementInfo().toString() + ", "
            + comp.getManagementInfo().getIpAddress()
             );
               TopologyNode node = (TopologyNode) comp;
               // ... do something with the node ...
           } else { // if (comp.isPeer())
               TopologyPeer peer = (TopologyPeer) comp;
               // retrieve the actual driver the peer refers to
               TopologyDriver actualDriver = manager.getDriver(peer.getUuid());
               // ... do something with the peer ...
           }
       }
   }
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2172
    • JPPF Web site
Re: How do I make use of transient JPPFSystemInformation ?
« Reply #1 on: April 07, 2017, 08:37:28 PM »

Hello,

Yes, the JPPFSystemInformation must be retrieved separately from the remote nodes. A good approach would be to have this done automatically when a node is added to the topology, by using a TopologyListener and implementing its nodeAdded() method.

For instance you could do like this:

Code: [Select]
public class MyTopologyListener extends TopologyListenerAdapter {
  @Override
  public void nodeAdded(TopologyEvent event) {
    TopologyNode node = event.getNodeOrPeer();
    if (node.isNode()) {
      TopologyDriver driver = node.getDriver();
      JMXDriverConnectionWrapper jmx = driver.getJmx();
      if ((jmx != null) && jmx.isConnected()) {
        try {
          JPPFNodeForwardingMBean forwarder = jmx.getNodeForwarder();
          NodeSelector selector = new UuidSelector(node.getUuid());
          Map<String, Object> result = forwarder.systemInformation(selector);
          Object o = result.get(node.getUuid());
          if (o instanceof JPPFSystemInformation) {
            JPPFSystemInformation info = (JPPFSystemInformation) o;
            node.getManagementInfo().setSystemInfo(info);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
}

Note the use of the node forwarding API (with the JPPFNodeForwardingMBean interface), so that we never have to connect directly to a node, and let the driver do the job instead.

The topology listener can then be registered when constructing the TopologyManager, like this:

Code: [Select]
TopologyManager manager = new TopologyManager(new MyTopologyListener());
Sincerely,
-Laurent
Logged
Pages: [1]   Go Up
 
JPPF Powered by SMF 2.0 RC5 | SMF © 2006–2011, Simple Machines LLC Get JPPF at SourceForge.net. Fast, secure and Free Open Source software downloads