Bug 845700 - Agent plug-in purge fails due to LIKE criteria in count query against rhq_resource_type table
Agent plug-in purge fails due to LIKE criteria in count query against rhq_res...
Status: CLOSED CURRENTRELEASE
Product: JBoss Operations Network
Classification: JBoss
Component: Inventory (Show other bugs)
JON 3.1.0
All All
urgent Severity high
: ---
: JON 3.1.2
Assigned To: John Sanda
Mike Foley
:
Depends On:
Blocks: 874123
  Show dependency treegraph
 
Reported: 2012-08-03 18:43 EDT by Larry O'Leary
Modified: 2013-09-11 06:59 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 874123 (view as bug list)
Environment:
Last Closed: 2013-09-11 06:59:25 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 178493 None None None 2012-08-03 21:37:27 EDT

  None (edit)
Description Larry O'Leary 2012-08-03 18:43:06 EDT
Description of problem:
User is unable to purge deleted plug-ins even though plug-in is marked deleted and eligible for purge. This is due to the following query PluginManagerBean.isReadyForPurge(Plugin plugin) using a LIKE query to verify all the plug-in's resource types have been deleted:

DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] SELECT COUNT(*)
FROM ResourceType resourcetype
WHERE ( LOWER( resourcetype.plugin )  like :pluginName ESCAPE '\\'  
AND resourcetype.deleted = :deleted )

2012-08-03 17:09:49,666 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (pluginName, %jbossas%)
2012-08-03 17:09:49,666 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (deleted, false)
2012-08-03 17:09:49,667 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryRunner] restriction=COUNT_ONLY, resultCount=49


In this case, the plug-in which was deleted is named JBossAS and all of its resource types have also been deleted. However, due to '%jbossas%' being bound to the :pluginName variable and the use of the LIKE comparison, the query returns a count of 49 rows due to the JBossAS5 plug-in also being installed.

Therefore, the JBossAS plug-in could only be purged if the JBossAS5 plug-in was also deleted -- which is undesirable.

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

How reproducible:
Always

Steps to Reproduce:
1.  Ensure JBoss AS 4 and AS 5 plug-ins are installed
2.  Import JBoss EAP 4.3 (profile: all) instance into inventory
3.  Delete JBossAS (4.x) and JBoss Cache (2.x) plug-ins

    *   Message center should show: Deleted agent plugins: [JBoss Application Server, JBossCache 2.x Services]

4.  Confirm plug-ins have been marked deleted

    *   From http://localhost:7080/coregui/#Test/ServerAccess/SQL execute:

            SELECT id,name,display_name,description,version,amps_version,enabled,status,path,md5,ctime,mtime,deployment FROM rhq_plugin WHERE deployment='AGENT' AND status='DELETED' ORDER BY name,id ASC;

        The result should contain the two deleted plug-ins with the name "JBossAS" and "JBossCache".
        
5.  Purge the plug-ins (Note: You must click Show Deleted to select the deleted plug-ins for purge)

    *   Message center should show: Preparing to purge agent plugins [JBoss Application Server, JBossCache 2.x Services]. This may take a few minutes ...

6.  Confirm the plug-ins have been purged
    After the purge was performed, the plug-ins should be purged within 5 minutes.
  
Actual results:
Even after 30 minutes, the JBossAS and JBossCache plug-ins have not been removed and server debug log reveals the following message each time plug-in purge job is executed:

DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] SELECT COUNT(*)
FROM ResourceType resourcetype
WHERE ( LOWER( resourcetype.plugin )  like :pluginName ESCAPE '\\'  
AND resourcetype.deleted = :deleted )

DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (pluginName, %jbossas%)
DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (deleted, false)
DEBUG [org.rhq.enterprise.server.util.CriteriaQueryRunner] restriction=COUNT_ONLY, resultCount=49

DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] SELECT COUNT(*)
FROM ResourceType resourcetype
WHERE ( LOWER( resourcetype.plugin )  like :pluginName ESCAPE '\\'  
AND resourcetype.deleted = :deleted )

DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (pluginName, %jbosscache%)
DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (deleted, false)
DEBUG [org.rhq.enterprise.server.util.CriteriaQueryRunner] restriction=COUNT_ONLY, resultCount=9


Expected results:
The JBossAS and JBossCache plug-ins should be removed from the rhq_plugin table and no longer appear on the agent plug-ins page in the UI.

Additional info:
Mazz tracked this down to the isReadyForPurge method itself. The method should use criteria.setStrict(true). It should also log at debug to indicate the actual count so that plug-in purge failure can be easily determined.
Comment 1 Charles Crouch 2012-08-13 12:12:13 EDT
As per triage: retarget at 312
Comment 2 John Sanda 2012-11-07 09:39:19 EST
PluginManagerBean.isReadyForPurge(Plugin) has been refactored so that the LIKE operator is not used in the resource type criteria. I have also added a test method  in PluginManagerBeanTest to cover this scenario. Lastly, a debug log statement that looks like the following has been added to isReadyForPurge,

<plugin> is not ready to be purged. There are still <resource_type_count> resource types in the system for this plugin.

master commit hashes:
cf039adcb51
2f891cc677
Comment 3 John Sanda 2012-11-07 09:59:44 EST
Changes have been pushed to the release/jon3.1.x branch.

commit hashes:
a77fb7ef8c9fe
687c313ad97f
Comment 5 Simeon Pinder 2012-11-14 23:53:42 EST
Moving this to ON_QA as available for testing in https://brewweb.devel.redhat.com//buildinfo?buildID=243389.
Comment 6 Sunil Kondkar 2012-12-05 04:42:00 EST
Verified on JON 3.1.2 ER2 build.

The plugins are removed from 'rhq_plugin' table. Below query returns empty set.

SELECT id,name,display_name,description,version,amps_version,enabled,status,path,md5,ctime,mtime,deployment FROM rhq_plugin WHERE deployment='AGENT' AND status='DELETED' ORDER BY name,id ASC;

The plugins does not appear on the 'Agent Plug-ins' page in the UI.

The server log shows below debug message:

2012-12-05 14:50:06,604 DEBUG [org.rhq.enterprise.server.resource.metadata.PluginManagerBean] AgentPlugin [id=10011, name=JBossAS, md5=5fad5b96751fa0ac672dbb587e9a0981] is not ready to be purged. It still has 27 resource types in the database.

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