CLI script call fails while cmdline interface works :-(

Andreas Dietrich adi at aspicon.de
Mon Apr 30 15:43:51 UTC 2012


Hey Lukas,

thanks for the quick reply. I'll try this. I should have had a closer 
look at the exception to see this as well :-/

Regards
Andreas :-)

On 30.04.2012 17:18, Lukas Krejci wrote:
>
> ----- Original Message -----
>> From: "Lukas Krejci"<lkrejci at redhat.com>
>> To: rhq-devel at lists.fedorahosted.org
>> Sent: Monday, April 30, 2012 5:14:28 PM
>> Subject: Re: CLI script call fails while cmdline interface works :-(
>>
>>
>> ----- Original Message -----
>>> From: "Andreas Dietrich"<adi at aspicon.de>
>>> To: rhq-devel at 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:
>>
> Oh! I even know what magic happens here! :)
>
> When you execute a line on the interactive commandline, the javascript interpreter sees that line as a source code and compiles it on the fly and is thus able to infer the types.
>
> When you pass your args from the commandline, it is not known how, where and when they are going to be used. So, as with the args passed to any Java or C program, all the arguments are strings. Therefore you need to use the "parseInt" function (a standard javascript function) to convert the type to a number.
>
>> 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 at lists.fedorahosted.org
>>> https://fedorahosted.org/mailman/listinfo/rhq-devel
>>>
> _______________________________________________
> rhq-devel mailing list
> rhq-devel at lists.fedorahosted.org
> https://fedorahosted.org/mailman/listinfo/rhq-devel



More information about the rhq-devel mailing list