Bug 1135473 - Implicit Variables for CLI are not available if the script is run as notification on an alert
Summary: Implicit Variables for CLI are not available if the script is run as notifica...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Operations Network
Classification: JBoss
Component: CLI
Version: JON 3.2.2
Hardware: All
OS: All
high
high
Target Milestone: ER04
: JON 3.3.0
Assignee: Thomas Segismont
QA Contact: Sunil Kondkar
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-08-29 12:17 UTC by dsteigne
Modified: 2018-12-09 18:28 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
When used as alert notifications, CLI scripts could not find Remote API entities unless they were declared with their fully qualified name. This was due to the script engine being initialized with an empty list of entity packages. In a standalone CLI environment, the list of packages was determined by scanning the "lib" directory of the CLI installation, which was not possible with an embedded CLI. As a consequence, the alert notification script execution failed with an error message similar to "javax.script.ScriptException:org.mozilla.javascript.EcmaError: ReferenceError: "ResourceCriteria" is not defined". Modifications to the script engine now initialize the embedded CLI with a list of packages determined by scanning the classpath at runtime. Remote API entities can now be declared with short names in CLI alert notification scripts.
Clone Of:
Environment:
Last Closed: 2014-12-11 14:04:14 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
test script with full path (327 bytes, text/plain)
2014-08-29 12:17 UTC, dsteigne
no flags Details
test script with implicit variable (298 bytes, text/plain)
2014-08-29 12:18 UTC, dsteigne
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 1181743 0 None None None Never

Description dsteigne 2014-08-29 12:17:17 UTC
Created attachment 932644 [details]
test script with full path

Description of problem:
It appears that when running a CLI Script as an Alert Notification Implicit Variables are not available (org.rhq.core.domain class is  not automatically imported)

Version-Release number of selected component (if applicable):
3.2.2

How reproducible:
Always

Steps to Reproduce:
1. Create an Alert Definition on any resource, i.e. Availability goes Down and add a Notification type of CLI Script, use the attached simplelist.js which simply uses var criteria = new ResourceCriteria(); to search for a resource type and print the list.
2. Trigger your Alert, look at the History on that Alert and you'll see the CLI notification fails with:
06:54:59,311 DEBUG [org.rhq.enterprise.server.alert.AlertManagerBean] (Thread-840) SenderResult{state=FAILURE, summary=Ran script simplelist.js in version rhqadmin:1.0 from repo Sample as user rhqadmin., successMessages=[], failureMessages=[javax.script.ScriptException:org.mozilla.javascript.EcmaError: ReferenceError: "ResourceCriteria" is not defined. (<Unknown source>#5) in <Unknown source> at line number 5 in script simplelist.js (rhqadmin:1.0) in repo Sample at line number 5]}

3. Now add another CLI notification to the same alert definition with the attached simplelistfqn.js which uses full path var criteria = new org.rhq.core.domain.criteria.ResourceCriteria(); it works.

Actual results:
Using Implicit variables in notification cli scripts fail.

Expected results:
Implicit variables would work.

Additional info:

Comment 1 dsteigne 2014-08-29 12:18:13 UTC
Created attachment 932656 [details]
test script with implicit variable

Comment 3 Thomas Segismont 2014-09-23 09:33:57 UTC
Fixed in master

commit daacc1cef59ea804c8a6b373366b00396da1961c
Author: Thomas Segismont <tsegismo>
Date:   Tue Sep 23 11:32:26 2014 +0200
    
    Script engine was initialized with an empty list of core domain packages.
    
    In the "real" CLI we can find it by scanning the lib directory. Here, we need to scan the core domain JAR by inspecting the classloader.
    
    Re-used org.jboss.jandex module from the EAP6.3 base instead of importing a new lib or writing our own code.

Comment 4 Libor Zoubek 2014-09-24 13:06:04 UTC
branch:  release/jon3.3.x
link:    https://github.com/rhq-project/rhq/commit/c5cc11a6a
time:    2014-09-24 15:05:16 +0200
commit:  c5cc11a6a3c5e927cd98f123a00b6c87aa722fda
author:  Thomas Segismont - tsegismo
message: Bug 1135473 - Implicit Variables for CLI are not available if the script
         is run as notification on an alert
         Script engine was initialized with an empty list of core domain
         packages.
         In the "real" CLI we can find it by scanning the lib directory.
         Here, we need to scan the core domain JAR by inspecting the
         classloader.
         Re-used org.jboss.jandex module from the EAP6.3 base instead of
         importing a new lib or writing our own code.
         (cherry picked from commit
         daacc1cef59ea804c8a6b373366b00396da1961c) Signed-off-by: Libor Zoubek <lzoubek>

Comment 5 Simeon Pinder 2014-10-01 21:33:09 UTC
Moving to ON_QA as available for test with build:
https://brewweb.devel.redhat.com/buildinfo?buildID=388959

Comment 7 Sunil Kondkar 2014-10-13 11:33:56 UTC
Verified on JON3.3 ER04

The alert history notification displays that the script simplelist.js ran successfully. Verified that both scripts does not display any failure in alert history notification.


Note You need to log in before you can comment on or make changes to this bug.