From d54dbec6b2c6025f4e00c035c8b2394d3151910f Mon Sep 17 00:00:00 2001 From: cvtienhoven Date: Wed, 15 Oct 2014 15:06:44 +0200 Subject: [PATCH 1/2] Added exec functionality Jolokia also support the exec function, which wasn't supported by jolokia-client. Added functionality to support this on single mbeans or array of mbeans (currently using the same operation and arguments for each mbean). --- lib/jolokia-client.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/jolokia-client.js b/lib/jolokia-client.js index 2f6b147..69d879c 100644 --- a/lib/jolokia-client.js +++ b/lib/jolokia-client.js @@ -196,6 +196,44 @@ Jolokia.prototype.dump = function(mbean, callback) { }); }; +Jolokia.prototype.exec = function(mbean, operation, arguments, callback) { + //mbean can be an array of mbeans, same operation is taken for all mbeans, arguments is an array. Supply [] for no arguments. + + if (!_.isArray(mbean)) { + requestJSON(this.url, { + "type" : "exec", + "mbean" : mbean, + "operation" : operation, + "arguments" : arguments + }, function(response) { + callback(response); + }); + return; + } + + var content = []; + + for ( var idx in mbean) { + var bean = mbean[idx]; + + content[idx] = _.isString(bean) ? { + "type" : "exec", + "mbean" : bean, + "operation" : operation, + "arguments" : arguments + } : { + "type" : "exec", + "mbean" : bean.mbean, + "operation" : operation, + "arguments" : arguments + }; + } + + requestJSON(this.url, content, function(response) { + callback(response); + }); +}; + // Exports // ---------------------------------------------------------------------------- From 261087b74140192e2b9fad2d69f17aeead66581e Mon Sep 17 00:00:00 2001 From: cvtienhoven Date: Wed, 15 Oct 2014 15:14:59 +0200 Subject: [PATCH 2/2] Added exec functionality --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 8f5c248..5a1fe00 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,24 @@ client.read([{mbean: "JMImplementation:type=MBeanServerDelegate", attribute="Imp }); ``` +### Exec mbean method + +#### client.exec(mbean, operation, arguments, callback) + +``` +//execute the operation "operation" on mbean1 with no arguments for the call: +client.exec("mbean1", "operation", [], function(result){ + console.log(...); +}); + +//execute the operation "operation" on all mbeans with "argument1" and "argument2" as arguments for each call: +client.exec(["mbean1","mbean2"], "operation", ["argument1", "argument2"], function(result){ + console.log(...); +}); + +``` + + jmx4node --------