Nodes management and monitoring via the driver

From JPPF Documentation

Jump to: navigation, search

Contents

Main Page > Management and monitoring > Node management via the driver

JPPF provides support for forwarding JMX requests to the nodes, along with receiving notifications from them, via the JPPF driver's JMX server. Which nodes are impacted is determined by a user-provided node selector.

This brings two major benefits:

  • this allows managing and monitoring the nodes in situations where the nodes are not reachable from the client, for instance when the client and nodes are on different networks or subnets
  • the requests and notification forwarding mechanism automatically adapts to node connection and disconnection events, which means that if new nodes are started in the grid, they will be automatically enrolled in the forwarding mechanism, provided they match the node selector

Node selectors

All the node forwarding APIs make use of node selectors to conveniently specify which nodes they apply to. A node selector is an instance of the NodeSelector interface, defined as follows:

 // Marker interface for selecting nodes
 public interface NodeSelector extends Serializable {
   // Constant for a selector which accepts all nodes
   NodeSelector ALL_NODES = new AllNodesSelector();
 
   // Selects all nodes
   public final static class AllNodesSelector implements NodeSelector {
     // Default constructor
     public AllNodesSelector()
   }
 
   // Selects nodes based on an execution policy
   public final static class ExecutionPolicySelector implements NodeSelector {
     // Initialize this selector with an execution policy
     public ExecutionPolicySelector(final ExecutionPolicy policy)
     // Get the execution policy to use to select the nodes
     public ExecutionPolicy getPolicy()
   }
 
   // Selects nodes based on their uuids
   public final static class UuidSelector implements NodeSelector {
     // Initialize this selector with a collection of node UUIDs
     public UuidSelector(final Collection<String> uuids)
     // Initialize this selector with an array of node UUIDs
     public UuidSelector(final String...uuids)
     // Get the collection of uuids of the nodes to select
     public Collection<String> getUuidList()
   }
 }

We can see that three types of selector are available:

Note that the node selection dynamically adjusts to the JPPF grid topology, or in other words two distinct selections with the same selector instance may return a different set of nodes: when new nodes are added to the grid or existing nodes are terminated, these changes in the toplogy will be automatically taken into account by the selection mechanism.

Forwarding management requests

The request forwarding mechanism is based on a built-in driver MBean: JPPFNodeForwardingMBean, which provides methods to invoke methods, or get or set attributes on remote node MBeans. Each of its methods requires a NodeSelector argument and an MBean name, to determine to which nodes, and which MBean in these nodes, the request will be performed. The return value is always a map of node UUIDs to the corresponding value returned by the request (if any) to the corresponding node. If an exception is raised when performing the request on a specific node, then that exception is returned in the map.

Here is an example:

 JPPFClient client = ...;
 AbstractJPPFClientConnection conn =
   (AbstractJPPFClientConnection) client.getClientConnection();
 JMXDriverConnectionWrapper driverJmx = conn.getJmxConnection();
 
 JPPFNodeForwardingMBean proxy = driverJmx.getProxy(
   JPPFNodeForwardingMBean.MBEAN_NAME, JPPFNodeForwardingMBean.class);
 
 // this selector selects all nodes attached to the driver
 NodeSelector selector = new NodeSelector.AllNodes();
 // this selector selects all nodes that have more than 2 processors
 ExecutionPolicy policy = new MoreThan("availableProcessors", 2);
 NodeSelector selector2 = new NodeSelector.ExecutionPolicySelector(policy);
 
 // invoke the state() method on the remote 'JPPFNodeAdminMBean' node MBeans
 // note that the MBean name does not need to be stated explicitely
 Map<String, Object> results = proxy.state(selector);
 // this is an exact equivalent, explicitely stating the target MBean on the nodes:
 String targetMBeanName = JPPFNodeAdminMBean.MBEAN_NAME;
 Map<String, Object> results2 = proxy.forwardInvoke(selector, targetMBeanName, "state");

 // handling the results
 for (Map.Entry<String, Object> entry: results) {
   if (entry.getValue() instanceof Exception) {
     // handle the exception ...
   } else {
     JPPFNodeState state = (JPPFNodeState) entry.getValue();
     // handle the result ...
   }
 }

Forwarding JMX notifications

JPPF provides a way to subscribe to notifications from a set of selected nodes, which differs from the one specified in the JMX API. This is due to the fact that the server-side mechanism for the registration of notification listeners is unspecified and thus provides no reliable way to override it.

To circumvent this difficulty, the registration of the notification listener is performed via the JMX client wrapper JMXDriverConnectionWrapper:

1) To add a notification listener, use registerForwardingNotificationListener(NodeSelector, String, NotificationListener, NotificationFilter, Object). This will register a notification listener for the specified MBean on each of the selected nodes. This method returns a listener ID which will be used to remove the notfication listener later on. Thus, the application must be careful to keep track of all registered listener IDs.

2) To remove a notification listener, use unregisterForwardingNotificationListener(String listenerID).


The notifications forwarded from the nodes are all wrapped into instances of JPPFNodeForwardingNotification. This class, which inherits from Notification, provides additional APIs to identify from which node and which MBean the notification was emitted.


The following code sample puts it all together:

 JPPFClient client = ...;
 AbstractJPPFClientConnection conn =
   (AbstractJPPFClientConnection) client.getClientConnection();
 JMXDriverConnectionWrapper driverJmx = conn.getJmxConnection();
 
 // this selector selects all nodes attached to the driver
 NodeSelector selector = new NodeSelector.AllNodes();
 
 // create a JMX notification listener
 NotificationListener myListener = new NotificationListener() {
   @Override
   public void handleNotification(Notification notification, Object handback) {
     JPPFNodeForwardingNotification wrapping =
       (JPPFNodeForwardingNotification) notification;
     System.out.println("received notification from nodeUuid=" + wrapping.getNodeUuid()
       + ", mBeanName=" + wrapping.getMBeanName());
     // get the actual notification sent by the node
     TaskExecutionNotification actualNotif =
       (TaskExecutionNotification) wrapping.getNotification();
     // handle the notification data ...
   }
 }
 
 // register the notification listener with the JPPFNodeTaskMonitorMBean
 // on the selected nodes
 String listenerID = driverJmx.registerForwardingNotificationListener(
   selector, JPPFNodeTaskMonitorMBean.MBEAN_NAME, listener, null, null);
 
 // ... submit a JPPF job ...
 
 // once the job has completed, unregister the notification listener
 driverJmx.unregisterForwardingNotificationListener(listenerID);
Main Page > Management and monitoring > Node management via the driver

Support This Project Powered by MediaWiki