Jenkins pipeline get JPPF node connected

Viewed 74

I am working in a project using Jenkins and JPPF. How do I get which node is connected to JPPF server? If possible, please give me the guideline detail. Thanks,

1 Answers

Disclaimer: JPPF developer here.

You can monitor the nodes connected to a JPPF server using the JMX-based server management APIs. There are many things you can monitor, and a lot of different information you can obtain from the server and the nodes. Hopefully, the following example will give you a good starting point:

// connect using a JMX remote connection wrapper
try (JMXDriverConnectionWrapper serverJmx = new JMXDriverConnectionWrapper("jppf_server_host", 11111)) {
  serverJmx.connectAndWait(5_000L);
  if (serverJmx.isConnected()) {
    // get summary information on all the connected nodes
    Collection<JPPFManagementInfo> nodeInfos = serverJmx.nodesInformation();
    System.out.println("there are " + nodeInfos.size() + " connected nodes:");
    for (JPPFManagementInfo info: nodeInfos) {
      System.out.println("node uuid: " + info.getUuid() + ", host is " + info.getHost());
    }

    // get detailed information on the nodes
    // the node forwarder will send the same request to all selected nodes
    // and group the results in a map where each key is a node uuid
    JPPFNodeForwardingMBean forwarder = serverJmx.getNodeForwarder();
    Map<String, Object> responses = forwarder.systemInformation(NodeSelector.ALL_NODES);
    for (Map.Entry<String, Object> response: responses.entrySet()) {
      String nodeUuid = response.getKey();
      if (response.getValue() instanceof Exception) {
        System.out.println("node with uuid = " + nodeUuid + " raised an exception:");
        ((Exception) response.getValue()).printStackTrace(System.out);
      } else {
        JPPFSystemInformation systemInfo = (JPPFSystemInformation) response.getValue();
        System.out.println("system properties for node uuid " + nodeUuid + " :");
        System.out.println(systemInfo.getSystem());
      }
    }

  } else {
    System.out.println("could not connect to jppf_server_host:11111");
  }
} catch (Exception e) {
  e.printStackTrace();
}

Note that the web and standalone administration consoles, which are built on top of the same management APIs, will also provide this information.

Related