Bug 828596

Summary: Agent fails to auto-discover JMX components with names bigger than 22 chars
Product: [Other] RHQ Project Reporter: Aurelio Calegari <aureliocalegari>
Component: AgentAssignee: Heiko W. Rupp <hrupp>
Status: NEW --- QA Contact: Mike Foley <mfoley>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 4.4CC: hrupp, jshaughn
Target Milestone: ---Flags: jshaughn: needinfo? (aureliocalegari)
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Aurelio Calegari 2012-06-04 20:21:09 EDT
Description of problem:

I have a JMX extended plugin which dynamically register components with the MBean server. I've created a plugin that has been working in RHQ 3.0.0. Here's the rhq-plugin.xml configuration.

			<c:simple-property name="objectName" readOnly="true"
				default="*:type=HttpMetricInspector,name=%name%" />
			<c:simple-property name="nameTemplate"
				default="Http metrics for endpoint {name}" />
			<c:simple-property name="descriptionTemplate"
				default="Http metrics for endpoint {name}" />
			<c:simple-property name="name" type="string"
				description="The actual MBean implementation name" />

The 'name' can be long. When RHQ discovers it and if there are 'names' that are bigger than 22, then it throws the following exception and don't register anything at all:

2012-06-05 09:44:14,483 INFO  [InventoryManager.availability-1] (rhq.core.pc.inventory.AvailabilityExecutor)- Scan Ended   : Tue Jun 05 09:44:14 EST 2012 : Scan [startTime=1338853452606, endTime=1338853454483, runtime=1877, isFull=false, isForced=false, numResources=77, numGetAvailabilityCalls=3, numScheduledRandomly=0, numPushedByInterval=2, numAvailabilityChanges=0, numDeferToParent=0]
2012-06-05 09:44:14,484 INFO  [InventoryManager.availability-1] (rhq.core.pc.inventory.AvailabilityExecutor)- Scan Starting: Tue Jun 05 09:44:14 EST 2012
2012-06-05 09:44:14,652 INFO  [InventoryManager.availability-1] (rhq.core.pc.inventory.AvailabilityExecutor)- Scan Ended   : Tue Jun 05 09:44:14 EST 2012 : Scan [startTime=1338853454484, endTime=1338853454652, runtime=168, isFull=false, isForced=false, numResources=77, numGetAvailabilityCalls=2, numScheduledRandomly=0, numPushedByInterval=1, numAvailabilityChanges=0, numDeferToParent=0]
2012-06-05 09:44:18,826 WARN  [InventoryManager.discovery-1] (rhq.core.pc.inventory.InventoryManager)- Failure during discovery for [Http Utilisation Service] Resources - failed after 513 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:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 22
        at java.lang.String.charAt(String.java:686)
        at java.util.regex.Matcher.appendReplacement(Matcher.java:703)
        at java.util.regex.Matcher.replaceAll(Matcher.java:813)
        at java.lang.String.replaceAll(String.java:2189)
        at org.rhq.plugins.jmx.util.ObjectNameQueryUtility.formatMessage(ObjectNameQueryUtility.java:126)
        at org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent.performDiscovery(MBeanResourceDiscoveryComponent.java:173)
        at org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent.discoverResources(MBeanResourceDiscoveryComponent.java:98)
        at org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent.discoverResources(MBeanResourceDiscoveryComponent.java:85)
        at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.rhq.core.pc.util.DiscoveryComponentProxyFactory$ComponentInvocationThread.call(DiscoveryComponentProxyFactory.java:293)
        ... 5 more
2012-06-05 09:44:31,633 INFO  [ResourceDiscoveryComponent.invoker.daemon-3] (org.rhq.plugins.agent.AgentEnvironmentScriptDiscoveryComponent)- Discovering RHQ Agent's environment setup script...
2012-06-05 09:44:31,634 INFO  [ResourceDiscoveryComponent.invoker.daemon-3] (org.rhq.plugins.agent.AgentLauncherScriptDiscoveryComponent)- Discovering RHQ Agent's launcher script service...

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

How reproducible:
Create a JMX Plugin which has in it's name a variable that might be longer than 22 chars. Run discovery command, then you should get the above exception

Steps to Reproduce:
Actual results:

Expected results:

Additional info:
I'm remotely connected to a JVM through JMX, so I had to manually import the JMX service (so the agent is efectivelly running in a different box). It inventories correctly the JVM components, but it fails to inventory the custom components if the dynamic portion of the names is big.
Comment 1 Jay Shaughnessy 2012-06-05 17:38:52 EDT
This seems unlikely, I'd guess it has more to do with what is in the name. The code that is failing involves doing replacements given the name template for the type.

Can you give us an example of an offending name?
Comment 2 Heiko W. Rupp 2012-07-18 15:26:39 EDT
do you have an example of a long object name that you want to match with that 
query, so that we can better look into it?

Comment 3 Heiko W. Rupp 2012-07-18 15:50:33 EDT
I've just put in a test for very long tokens as in 
        testON = new 

and this looks good.

Does your token perhaps have a "strange" character?