----- Original Message -----
From: "Andreas Dietrich" <adi(a)aspicon.de>
To: rhq-devel(a)lists.fedorahosted.org
Sent: Monday, April 30, 2012 4:59:21 PM
Subject: CLI script call fails while cmdline interface works :-(
Hi,
I wrote the following script (myscript.js):
function reenableSchedules(resourceId) {
var crit = new MeasurementScheduleCriteria();
crit.addFilterEnabled(true);
crit.addFilterResourceId(resourceId);
var scheds =
MeasurementScheduleManager.findSchedulesByCriteria(crit);
var mdefIds = [];
for (var s=0; s < scheds.length; s++)
mdefIds[s] = scheds[s].definition.id;
MeasurementScheduleManager.enableSchedulesForResource(resourceId,
mdefIds);
}
reenableSchedules(resId); // resId must be provided from the outside
Executing it with "rhq-remoting-cli-4.3.0/bin/rhq-cli.sh -u rhqadmin
-p
<admpass> -s localhost -t 7080 --args-style=named -f myscript.js
resId=0
returns:
Remote server version is: 4.3.0 (a9b2a27)
Login successful
Exception in thread "Main Thread"
org.rhq.enterprise.client.script.CLIScriptException:
javax.script.ScriptException:
sun.org.mozilla.javascript.internal.EvaluatorException: Can't find
method
org.rhq.core.domain.criteria.MeasurementScheduleCriteria.addFilterResourceId(string).
(<Unknown source>#4) in <Unknown source> at line number 4
at
org.rhq.enterprise.client.commands.ScriptCommand.executeScriptFile(ScriptCommand.java:298)
at
org.rhq.enterprise.client.commands.ScriptCommand.execute(ScriptCommand.java:108)
at
org.rhq.enterprise.client.ClientMain$StartupConfiguration.process(ClientMain.java:142)
at
org.rhq.enterprise.client.ClientMain.main(ClientMain.java:164)
Caused by: javax.script.ScriptException:
sun.org.mozilla.javascript.internal.EvaluatorException: Can't find
method
org.rhq.core.domain.criteria.MeasurementScheduleCriteria.addFilterResourceId(string).
(<Unknown source>#4) in <Unknown source> at line number 4
at
com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:153)
at
javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:232)
at
org.rhq.enterprise.client.commands.ScriptCommand.executeScriptFile(ScriptCommand.java:287)
... 3 more
When I execute the above lines in the cmdline interface everything
works
(I just copy/pasted the code inside the function line-by-line and set
a
value for resourceId. :-(
while I'm not exactly sure what magic happens on the commandline that the automatic
type conversion works, you might try to replace:
reenableSchedules(resId);
with:
reeanbleSchedules(parseInt(resId));
Another (little) unrelated question would be how I can read indexed
parameters in the script. I.e. if I like to call it "... myscript.js
123" and not "... myscript.js resId=123"?
This is NOT available in the interactive CLI, but when you execute a script using an -f
option, you should have a variable called "args" available that should contain
your commandline arguments to the script indexed by their position.
Kind regards
Andreas :-)
_______________________________________________
rhq-devel mailing list
rhq-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/rhq-devel