Bug 874123 - Agent plug-in purge fails due to LIKE criteria in count query against rhq_resource_type table
Summary: Agent plug-in purge fails due to LIKE criteria in count query against rhq_res...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: Inventory
Version: 4.5
Hardware: All
OS: All
urgent
high
Target Milestone: ---
: RHQ 4.6
Assignee: John Sanda
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On: 845700
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-11-07 14:56 UTC by John Sanda
Modified: 2013-09-03 14:43 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 845700
Environment:
Last Closed: 2013-09-03 14:43:29 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 178493 0 None None None 2012-11-07 14:56:04 UTC

Description John Sanda 2012-11-07 14:56:03 UTC
+++ This bug was initially created as a clone of Bug #845700 +++

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.

--- Additional comment from ccrouch on 2012-08-13 12:12:13 EDT ---

As per triage: retarget at 312

--- Additional comment from jsanda on 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 1 John Sanda 2012-11-07 14:56:54 UTC
Moving to ON_QA since changes have been pushed to master.

Comment 2 Heiko W. Rupp 2013-09-03 14:43:29 UTC
Bulk closing of issues in old RHQ releases that are in production for a while now.

Please open a new issue when running into an issue.


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