Bug 766574

Summary: ResourceManager NullPointerException using autoImport.js
Product: [Other] RHQ Project Reporter: Nabeel Saad <nsaad>
Component: CLIAssignee: John Mazzitelli <mazz>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: high Docs Contact:
Priority: high    
Version: 3.0.0CC: gcooper, hrupp, loleary, mazz, sappleto
Target Milestone: ---   
Target Release: RHQ 4.3.0   
Hardware: Unspecified   
OS: Unspecified   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 781867 784361 (view as bug list) Environment:
Last Closed: 2013-08-31 10:14:44 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 760116, 784361    
Description Flags
Auto import script none

Description Nabeel Saad 2011-12-12 11:12:08 UTC
Created attachment 545664 [details]
Auto import script

Description of problem:

I have a JS script called autoImport.js that worked in JON v2.4.1 and all the different JON 3 beta/release candidate versions.  However, running it again JON 3.0.0, it seems to throw a couple of different errors.

Trying to run through it manually I've hit an error that I don't see when I run the script in it's entirety:
   var criteria = ResourceCriteria();

Throws the following error (in the CLI remoting tool):
	at org.rhq.bindings.output.TabularWriter.shortVersion(TabularWriter.java:674)
	at org.rhq.bindings.output.TabularWriter.print(TabularWriter.java:337)
	at org.rhq.bindings.output.TabularWriter.print(TabularWriter.java:123)
	at org.rhq.enterprise.client.commands.ScriptCommand.execute(ScriptCommand.java:159)
	at org.rhq.enterprise.client.ClientMain.executePromptCommand(ClientMain.java:317)
	at org.rhq.enterprise.client.ClientMain$1.run(ClientMain.java:262)
	at java.lang.Thread.run(Thread.java:662)

This seems to be explicitly related to the line:

If I leave it out, I don't get an error, just "no data" as the result.  If I modify it to use any other InventoryStatus options, it seems to work as well, but it is a vanilla JON Server so the only resources to be found are "NEW" ones.

I tried importing my resource, running the ResourceManager command with "InventoryStatus.COMMITTED" and that worked fine.  I then uninventoried the resource and re-ran the command with "InventoryStatus.NEW" and this time did not get the NullPointerException.

When I run the attached importResources.js using "exec -f autoImport.js", it doesn't throw this error, but it seems to complain about the line:

With the following error:
    sun.org.mozilla.javascript.internal.WrappedException: Wrapped javax.naming.NameNotFoundException: [Warning] remote not bound (<Unknown source>#11) in <Unknown source> at line number 11

Although if I do just type:

into the CLI tool, it returns "Proxy17" which implies it's finding it.  Adding a dot (.) I do get auto-completion.

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

How reproducible:
every time

Steps to Reproduce:
1.  Setup a new JON Server with a resource in the discovery queue
2.  Run the autoImport.js via the CLI tool
3.  You should see the error thrown in the CLI
Actual results:
Resource is not imported

Expected results:
Resource should be imported

Additional info:

Comment 1 John Mazzitelli 2011-12-20 19:37:41 UTC
> at org.rhq.bindings.output.TabularWriter.shortVersion(TabularWriter.java:674)

that line number doesn't match the latest code. I suspect an older version (whose code DOES match up with this line number) is being used - which means there may be compatibility issues.

In any event, I do see where a possible NPE can occur in the shortVersion() method. I'll check in a fix for that one.

Comment 2 John Mazzitelli 2011-12-20 19:42:03 UTC
git master commit: a638398

-            return ((ResourceAvailability) object).getAvailabilityType().getName();
+            AvailabilityType availType = ((ResourceAvailability) object).getAvailabilityType();
+            return (availType == null) ? "?" : availType.getName();

this fixes the first problem described in this BZ

Comment 3 John Mazzitelli 2011-12-20 19:54:49 UTC
BTW: to test this first fix, log into the CLI and enter this:

   var criteria = ResourceCriteria();

Rather than get an NPE, you should now see the list of resources that are new, with a currentAvailability set to "?" - meaning we haven't received any avail data (which is to be expected for resources not yet in inventory). e.g.:

id    name                version             currentAvailability resourceType      
10001 myhost              Linux ?                   Linux             
10014 RHQ Agent           4.3.0-SNAPSHOT      ?                   RHQ Agent         
10015 myhost:2099 RHQ     AS 4.2.3.GA         ?                   JBossAS Server    

Comment 4 John Mazzitelli 2011-12-20 20:06:54 UTC
as for the second problem, this is the server-side error/stack that I get:

15:02:41,814 ERROR [RemoteSafeInvocationHandler] Failed to invoke remote request
javax.naming.NameNotFoundException: remote not bound
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
        at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
        at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
        at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
        at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at org.rhq.enterprise.server.remote.RemoteSafeInvocationHandler.invoke(RemoteSafeInvocationHandler.java:98)
        at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:809)
        at org.jboss.remoting.transport.servlet.ServletServerInvoker.processRequest(ServletServerInvoker.java:232)
        at sun.reflect.GeneratedMethodAccessor235.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:288)
        at $Proxy506.processRequest(Unknown Source)
        at org.jboss.remoting.transport.servlet.web.ServerInvokerServlet.processRequest(ServerInvokerServlet.java:128)
        at org.jboss.remoting.transport.servlet.web.ServerInvokerServlet.doPost(ServerInvokerServlet.java:157)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

Comment 5 John Mazzitelli 2011-12-20 20:20:40 UTC
this error is due to a jndi lookup failing to find "rhq/DiscoveryBossBean/remote" - not sure why this is a problem

Comment 6 John Mazzitelli 2011-12-20 21:22:55 UTC
i think this is because someone checked in this change:

- public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemote {
+ public class DiscoveryBossBean implements DiscoveryBossLocal {

They removed the explicit implementation of the DiscoveryBossRemote. I'm thinking this might be why this is no longer working. Dammit. I don't know why this change was made, but I have a feeling there was no reason for it.

Comment 7 John Mazzitelli 2011-12-20 21:32:03 UTC
marking this to be included in jon3.0.1 - this is bad. this past change apparently made the discovery SLSB no longer accessible from remote clients/cli

Comment 8 John Mazzitelli 2011-12-20 22:28:49 UTC
master commit: 74fe0df

Comment 11 Mike Foley 2011-12-21 21:07:52 UTC
verified rhq master 4.3

Comment 14 Heiko W. Rupp 2013-08-31 10:14:44 UTC
Bulk close of old bugs in VERIFIED state.