Bug 907558 - [jboss-as-7] Discovery fails for AS 7 domain when AS was started with -P command-line argument
[jboss-as-7] Discovery fails for AS 7 domain when AS was started with -P comm...
Status: ON_QA
Product: RHQ Project
Classification: Other
Component: Plugins (Show other bugs)
4.5
All All
unspecified Severity high (vote)
: ---
: ---
Assigned To: RHQ Project Maintainer
Mike Foley
:
Depends On:
Blocks: 906579
  Show dependency treegraph
 
Reported: 2013-02-04 12:33 EST by Lukas Krejci
Modified: 2013-02-06 11:01 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 906579
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Lukas Krejci 2013-02-04 12:33:21 EST
+++ This bug was initially created as a clone of Bug #906579 +++

Description of problem:
When -P/--properties command-line option is passed to domain.sh, jboss-as-7 plug-in fails to execute discovery due to:

    ERROR [ResourceDiscoveryComponent.invoker.daemon-1] (rhq.modules.plugins.jbossas7.HostControllerDiscovery)- Discovery of a JBossAS7 Host Controller Resource failed for process: pid=[8729], name=[/etc/alternatives/java_sdk/bin/java], ppid=[8712].
    java.lang.NullPointerException
        at org.rhq.modules.plugins.jbossas7.AS7CommandLine.getAbsoluteFile(AS7CommandLine.java:185)
        at org.rhq.modules.plugins.jbossas7.AS7CommandLine.toURL(AS7CommandLine.java:161)
        at org.rhq.modules.plugins.jbossas7.AS7CommandLine.processClassArgument(AS7CommandLine.java:132)
        at org.rhq.core.pluginapi.util.JavaCommandLine.parseClassArguments(JavaCommandLine.java:194)
        at org.rhq.core.pluginapi.util.JavaCommandLine.parseCommandLine(JavaCommandLine.java:159)
        at org.rhq.core.pluginapi.util.JavaCommandLine.<init>(JavaCommandLine.java:136)
        at org.rhq.modules.plugins.jbossas7.AS7CommandLine.<init>(AS7CommandLine.java:69)
        at org.rhq.modules.plugins.jbossas7.AS7CommandLine.<init>(AS7CommandLine.java:74)
        at org.rhq.modules.plugins.jbossas7.BaseProcessDiscovery.discoverResources(BaseProcessDiscovery.java:135)
        at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.rhq.core.pc.util.DiscoveryComponentProxyFactory$ComponentInvocationThread.call(DiscoveryComponentProxyFactory.java:293)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:636)


Version-Release number of selected component (if applicable):
4.4.0.JON312GA

How reproducible:
Always

Steps to Reproduce:
1.  Install EAP 6
2.  Create empty system.properties file:

        touch "${JBOSS_HOME}/bin/system.properties"
        
3.  Start EAP domain with -P command-line argument passing the relative path value system.properties:

        cd "${JBOSS_HOME}/bin"
        ./domain.sh -P system.properties

4.  Start JBoss ON system
5.  Wait for server discovery to execute

Actual results:
AS/EAP domain is not discovered and agent log contains the following error:
    ERROR [ResourceDiscoveryComponent.invoker.daemon-1] (rhq.modules.plugins.jbossas7.HostControllerDiscovery)- Discovery of a JBossAS7 Host Controller Resource failed for process: pid=[8729], name=[/etc/alternatives/java_sdk/bin/java], ppid=[8712].
    java.lang.NullPointerException
        at org.rhq.modules.plugins.jbossas7.AS7CommandLine.getAbsoluteFile(AS7CommandLine.java:185)

Expected results:
AS/EAP domain should be discovered.

Additional info:
This is just the surface of the issue. Specifically, the exception is caused by the attempted use of the this.log which has not yet been initialized seeing that the constructor is still being executed. 

The next issue is that this.process is referenced yet it also has not been initialized because it doesn't get initialized until later.

Finally, as a last resort an attempt is made to read the jboss.home.dir property to make the path to --properties absolute but that system property has not yet been parsed and therefore is not yet defined. 

So, to fix this, we must first fix the inheritance issue. We should not be invoking private/protected non-static methods from the constructors that require an already initialized instance of the class. This can be seen in the log and process fields of the class. 

Then, we should probably add logic to handle the situation of jboss.home.dir not yet being defined:

                String homeDir = getSystemProperties().get(HOME_DIR_SYSPROP);
                if (homeDir != null) {
                    File binDir = new File(homeDir, "bin");
                    absoluteFile = new File(binDir, file.getPath());
                } else {
                ...

to:

                String homeDir = getSystemProperties().get(HOME_DIR_SYSPROP);
                if (homeDir == null) {
                    List<String> args = this.getArguments();
                    if (args != null) {
                        for (String arg : args) {
                            if ( arg != null && arg.startsWith("-D" + HOME_DIR_SYSPROP + "=")) {
                                ...
                            }
                        }
                    }
                }
                if (homeDir != null) {
                    File binDir = new File(homeDir, "bin");
                    absoluteFile = new File(binDir, file.getPath());
                } else {

--- Additional comment from Lukas Krejci on 2013-02-01 09:30:36 EST ---

The code as it is right now both in the generic JavaCommandLine and in the concrete AS7CommandLine will have to be reworked. Calling overriden methods in the super constructor is just a bad idea.
Comment 1 Lukas Krejci 2013-02-04 13:09:58 EST
master http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=2910d155e509b6ebccdc9483a70b2910bdf0133c
Author: Lukas Krejci <lkrejci@redhat.com>
Date:   Mon Feb 4 18:53:21 2013 +0100

    [BZ 907558] - JavaCommandLine and subclasses now parse the commandline lazily
    to prevent calling overriden methods in super-class constructor.
    A couple of other cosmetic improvements like static logger, etc.
Comment 2 Larry O'Leary 2013-02-06 10:55:28 EST
Appears this fix may have introduced a new failure. I have only tested this against the JBoss ON release branch but it appears that it may also apply to the master branch. Any thoughts?

2013-02-06 09:36:54,077 WARN  [InventoryManager.discovery-1] (rhq.core.pc.inventory.InventoryManager)- Failure during discovery for [JBossAS7 Standalone Server] Resources - failed after 150 ms.
java.lang.Exception: Discovery component invocation failed.
	at org.rhq.core.pc.util.DiscoveryComponentProxyFactory$ComponentInvocationThread.call(DiscoveryComponentProxyFactory.java:297)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NoSuchMethodError: org.rhq.modules.plugins.jbossas7.AS7CommandLine.isArgumentsParsed()Z
	at org.rhq.modules.plugins.jbossas7.AS7CommandLine.getAppServerArguments(AS7CommandLine.java:89)
	at org.rhq.modules.plugins.jbossas7.BaseProcessDiscovery.setStartScriptPluginConfigProps(BaseProcessDiscovery.java:277)
	at org.rhq.modules.plugins.jbossas7.BaseProcessDiscovery.buildResourceDetails(BaseProcessDiscovery.java:198)
	at org.rhq.modules.plugins.jbossas7.StandaloneASDiscovery.buildResourceDetails(StandaloneASDiscovery.java:84)
	at org.rhq.modules.plugins.jbossas7.BaseProcessDiscovery.discoverResources(BaseProcessDiscovery.java:136)
	at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.rhq.core.pc.util.DiscoveryComponentProxyFactory$ComponentInvocationThread.call(DiscoveryComponentProxyFactory.java:293)
	... 5 more


Setting to ON_DEV and will update the upstream bug(s).
Comment 3 Lukas Krejci 2013-02-06 10:58:58 EST
isArgumentsParsed is a method in JavaCommandLine class which is in rhq-core-plugin-api-XXX.jar.

Have you updated that, too, on the agent?
Comment 4 Larry O'Leary 2013-02-06 11:01:17 EST
Ah, thank you. I see this now. So, this can't be done as a patch. :(

But this is still good in master. I am resetting status to ON_QA.

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