Bug 928971 - No *Manager or ProxyFactory works in CLI alert scripts
Summary: No *Manager or ProxyFactory works in CLI alert scripts
Keywords:
Status: ON_QA
Alias: None
Product: RHQ Project
Classification: Other
Component: Alerts, CLI
Version: 4.6
Hardware: Unspecified
OS: Unspecified
unspecified
urgent
Target Milestone: ---
: ---
Assignee: Nobody
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-03-28 21:37 UTC by Lukas Krejci
Modified: 2022-03-31 04:27 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Embargoed:


Attachments (Terms of Use)

Description Lukas Krejci 2013-03-28 21:37:54 UTC
Description of problem:
The ProxyFactory.getResource() method fails to create the proxies to the resources in the RHQ server environment with the following error message:

21:57:36,973 ERROR [org.rhq.bindings.client.ResourceClientFactory] (Script Runner for alert org.rhq.core.domain.alert.Alert[id=10491, alertDefinition=org.rhq.core.domain.alert.AlertDefinition[ id=10011, name=test, conditionExpression=ANY, priority=Medium, resourceId=10001 ], ctime=1364504253870]) Could not create custom interface for resource with id 10001: javassist.NotFoundException: org.rhq.bindings.client.ResourceClientProxy$Measurement
        at javassist.ClassPool.get(ClassPool.java:440) [javassist-3.15.0-GA.jar:3.15.0.GA]
        at org.rhq.bindings.client.ResourceClientFactory.defineCustomInterface(ResourceClientFactory.java:161) [rhq-script-bindings-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.rhq.bindings.client.ResourceClientFactory.getResource(ResourceClientFactory.java:79) [rhq-script-bindings-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_10]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_10]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_10]
        at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_10]
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1473) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.rhq.scripting.javascript.engine.RhinoScriptEngine$1.superDoTopCall(RhinoScriptEngine.java:235) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.rhq.scripting.javascript.engine.RhinoScriptEngine$1.access$000(RhinoScriptEngine.java:199) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.rhq.scripting.javascript.engine.RhinoScriptEngine$1$1.run(RhinoScriptEngine.java:215) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_10]
        at org.rhq.scripting.javascript.engine.RhinoScriptEngine$1.doTopCall(RhinoScriptEngine.java:212) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.mozilla.javascript.Context.evaluateReader(Context.java:1110) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at org.rhq.scripting.javascript.engine.RhinoScriptEngine.eval(RhinoScriptEngine.java:363) [rhq-scripting-javascript-4.7.0-SNAPSHOT.jar:4.7.0-SNAPSHOT]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) [rt.jar:1.7.0_10]
        at org.rhq.enterprise.server.plugins.alertCli.CliSender$1.run(CliSender.java:168)
        at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_10]


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

How reproducible:
always

Steps to Reproduce:
1. Attach the following script as the CLI script on an alert definition on some platform resource:

var myResource = ProxyFactory.getResource(alert.alertDefinition.resource.id);
myResource.viewProcessList();

2. Let the alert fire.
  
Actual results:
The above mentioned exception will appear in the server log and the CLI script will fail with a complaint that no method "viewProcessList" exists on the object.


Expected results:
no exception in the server log, the script works without error.

Additional info:

This is most probably a classloading issue...

Comment 1 Lukas Krejci 2013-03-28 22:06:40 UTC
Actually this is unbelievably more serious than the description - no *Manager can't be used either, making CLI alert scripts completely unusable.

Updating the title of the bug to reflect that.

Comment 2 Lukas Krejci 2013-03-29 15:17:12 UTC
http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=fe8952cf9631c2d839f9e37d53f8c1aa1bb04b83

master fe8952cf9631c2d839f9e37d53f8c1aa1bb04b83
Author: Lukas Krejci <lkrejci>
Date:   Fri Mar 29 16:06:45 2013 +0100

    Fix classloading issues when defining objects in the std script context.
    
    It seems that the change of the container to AS7 has caused a regression
    in the CLI alert scripts that were no longer able to properly define the
    standard context provided to scripts by RHQ.
    
    This is fixed by using a differently configured Javassist's ClassPool
    during the various class modifications we use to prepare the *Manager
    objects and when generating a resource proxy in ProxyFactory.
    
    Also, the errors that can happen during the various stages of this setup
    are now thrown up the chain instead of merely logged so that errors like
    this are apparent - it is not something the user should be expected to
    deal with.

Comment 3 Lukas Krejci 2013-03-29 16:09:28 UTC
http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=99bbd52d13b16fe57c80c6dab7230942cfd49560

commit 99bbd52d13b16fe57c80c6dab7230942cfd49560
Author: Lukas Krejci <lkrejci>
Date:   Fri Mar 29 17:04:21 2013 +0100

    [BZ 928971] - ClassPoolFactory is now resilient against context classloader changes
    
    The instance must not be cached because it could be using a wrong context
    classloader if that changed between invocations.
    
    Also made changes to lower the numbder of instances of the ClassPool
    in the created while using the ConfigurationClassBuilder.
    
    This, in addition to commit fe8952cf9631c2d839f9e37d53f8c1aa1bb04b83
    (which I failed to annotate with the BZ number), should fix the bug.

Comment 4 Lukas Krejci 2013-04-03 12:29:54 UTC
http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=1d605edf14fde97c3986fd376e5f41d7e6194bae

commit 1d605edf14fde97c3986fd376e5f41d7e6194bae
Author: Lukas Krejci <lkrejci>
Date:   Wed Apr 3 14:28:57 2013 +0200

    [BZ 928971] - Return the same class pool for the same context classloader
    so that the class cache of the class pool is consistent with what has
    been defined using given classloader. This should prevent the possible
    linkage errors when trying to define a single class multiple times in the
    same classloader which could have happened before this change.

Comment 7 Lukas Krejci 2013-04-03 18:18:59 UTC
http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=014545b4e2ac3ac07413ffae42a2b06e0e5926ed

commit 014545b4e2ac3ac07413ffae42a2b06e0e5926ed
Author: Lukas Krejci <lkrejci>
Date:   Wed Apr 3 20:17:49 2013 +0200

    [BZ 928971] - Set the correct classloader for the dynamically created
    resource proxy classes.


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